1 Attachment(s)
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 -
Quote:
The column cannot contain null values. [Column name = ID, Table name = Pipeline ]
The ID Column in the table has this configuration
Attachment 101335
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
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?
Re: SQL Server Compact and INSERT Statement
Thanks, I revised the column configurations in the table and it works fine.
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
Re: SQL Server Compact and INSERT Statement
Quote:
Originally Posted by
harsh288
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.