|
-
Jun 18th, 2013, 06:33 PM
#1
Thread Starter
Lively Member
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

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
-
Jun 18th, 2013, 07:06 PM
#2
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?
-
Jun 19th, 2013, 09:31 PM
#3
Thread Starter
Lively Member
Re: SQL Server Compact and INSERT Statement
Thanks, I revised the column configurations in the table and it works fine.
-
Jun 19th, 2013, 10:07 PM
#4
Lively Member
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
-
Jun 19th, 2013, 11:10 PM
#5
Re: SQL Server Compact and INSERT Statement
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|