Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42340

VS 2012 SQL Server Compact and INSERT Statement

$
0
0
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 -

Quote:

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: 10
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

Attached Images
 

Viewing all articles
Browse latest Browse all 42340

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>