Results 1 to 5 of 5

Thread: SQL Server Compact and INSERT Statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    72

    SQL Server Compact and INSERT Statement

    Hi,

    I am trying to insert some data into a SQL Server CE from a Windows Form.

    I keep getting errors and I dont know why, the error code i receive is -

    The column cannot contain null values. [Column name = ID, Table name = Pipeline ]
    The ID Column in the table has this configuration

    Name:  Untitled.jpg
Views: 506
Size:  59.5 KB

    I think I have configured the column correctly and I would have thought that this value would be auto generated.

    My code is shown below, can anyone help?

    Code:
      Dim sqlInsertValues As String = "INSERT INTO [Pipeline] ([Reference Code],[Account Manager],[Client]," & _
                "[Industry Type],[Date Approached],[Proposal Provided],[Status],[Start Date],[Follow Up Date],[Expected Revenue],[Comments]) " & _
                "VALUES (@ReferenceCode,@AccountManager,@Client,@IndustryType,@DateApproached,@ProposalProvided,@Status,@StartDate,@FollowUpDate,@ExpectedRevenue,@Comments)"
    
            If SISCon.State = ConnectionState.Closed Then
                SISCon.ConnectionString = ConnStr
                SISCon.Open()
            End If
    
            Dim sqlInsertParameter As SqlCeCommand = New SqlCeCommand(sqlInsertValues, SISCon)
    
            With sqlInsertParameter.Parameters
                .AddWithValue("@ReferenceCode", refcodetb)
                .AddWithValue("@AccountManager", ACCTMANAGERCB)
                .AddWithValue("@Client", ClientTB)
                .AddWithValue("@IndustryType", INDUSTRYTYPECB)
                .AddWithValue("@DateApproached", DATEAPPROACHED.Value)
                .AddWithValue("@ProposalProvided", PROPOSALPROVIDEDCB)
                .AddWithValue("@Status", STATUSCB)
                .AddWithValue("@StartDate", STARTDATE.Value)
                .AddWithValue("@FollowUpDate", FOLLOWUPDATE.Value)
                .AddWithValue("@ExpectedRevenue", ExpectedRevenueFigure)
                .AddWithValue("@Comments", COMMENTSRTB)
            End With
    
            Try
                sqlInsertParameter.ExecuteNonQuery()
              
                SISCon.Close()
                MsgBox("Data commited successfully")
    
            Catch ex As Exception
                ' Show the exception's message.
                MessageBox.Show(ex.Message)
    
                ' Show the stack trace, which is a list of methods 
                ' that are currently executing.
                MessageBox.Show("Stack Trace: " & vbCrLf & ex.StackTrace)
    
            End Try

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: SQL Server Compact and INSERT Statement

    That's the configuration of the ID column in your DataTable, which you're not even using in that code. What's the configuration of the corresponding database column?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    72

    Re: SQL Server Compact and INSERT Statement

    Thanks, I revised the column configurations in the table and it works fine.

  4. #4
    Lively Member
    Join Date
    Jan 2012
    Posts
    100

    Re: SQL Server Compact and INSERT Statement

    Hello AC1982,

    Are you using SQL server compact for windows mobile, if yes could you please help me

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: SQL Server Compact and INSERT Statement

    Quote Originally Posted by harsh288 View Post
    Hello AC1982,

    Are you using SQL server compact for windows mobile, if yes could you please help me
    If you have a question that relates specifically to the topic of this thread then just ask it, rather than asking if you can ask it. If it doesn't relate specifically to the topic of this thread then start a new thread for your question. Either way, then anyone can answer your question. If you want someone specific to take a look at your thread then send them a PM and provide a link.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width