I'm calling a GUID with a system function and trying to insert it into a database as a primary key. i'm using vb 2010 .net framework with sqlce server making my datatables. the column is AutoNumber which i set up to be a uniqueidentifier. the length is not adjustable and set at 16. i got all kinds of not parsing query errors. i've edited the insert statement a bunch trying to figure this out. i've went so far as changing the table schema of AutoNumber to be just a nvarchar with length of 100. it's something to do with how i'm inserting the GUID. in the code below i'm converting it into a string then inserting it into my table. is this wrong?? i've tried finding other ways of doing it but it's a little confusing. everything else in the code works perfectly it's just this part that is keeping me from completion.
Private Sub saveandexitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveandexitbutton.Click
Dim check As Integer
Dim mycon As SqlCeConnection
Dim mycmd1 As New SqlCeCommand
Dim myDA As New SqlCeDataAdapter
Dim myDS As New DataSet
Dim myDT As New DataTable
Dim cline As String
Dim autonumber As String
cline = linecbo.SelectedValue
If shiftstatus <> "1" And shiftstatus <> "2" Then
MsgBox("Please Select Shift", MsgBoxStyle.OkOnly, "Message")
ElseIf linecbo.SelectedIndex = -1 Or frm3machinecbo.SelectedIndex = -1 Or possiblecausetxtbox.Text = "" Or descriptiontxtbox.Text = "" _
Or estimatedtxt.Text = "" Then
MsgBox("Please Fill in Data Fields", MsgBoxStyle.OkOnly, "Message")
ElseIf MsgBox("Are you sure you want to save information?", MsgBoxStyle.OkCancel, "Message") = MsgBoxResult.Cancel Then
'do nothing
Else
Try
mycon = GetConnect()
mycon.Open()
autonumber = System.Guid.NewGuid.ToString
mycmd1 = mycon.CreateCommand
mycmd1.CommandText = "INSERT INTO baseform(AutoNumber, Date, Shift, MechanicName, LineNumber, Machine, EstimatedTime, RootCause, BriefDescription) '" & _
"'VALUES('" & autonumber & "','" & datetxtbox.Text & "','" & shiftstatus & "','" & fullnametxtbox.Text & _
"','" & linecbo.SelectedValue & "','" & frm3machinecbo.SelectedValue & "','" & estimatedtxt.Text & _
"','" & Trim(possiblecausetxtbox.Text) & "','" & Trim(descriptiontxtbox.Text) & "')"
check = mycmd1.ExecuteReader.RecordsAffected()
If check > 0 Then
MsgBox("Mechanic with ID " & Trim(fullnametxtbox.Text) & " successfully added", MsgBoxStyle.OkOnly, "Message :")
Else
MsgBox("Mechanic with ID " & Trim(fullnametxtbox.Text) & " failed to add", MsgBoxStyle.OkOnly, "Message :")
End If
mycmd1.ExecuteNonQuery()
DataEntry_Refresh_Form()
mycon.Close()
Me.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error!!")
End Try
End If
End Sub
any help would be appreciated. i'm sure it's just a simple fix but it's escaping me.
Thanks,