SQL insert

  • Thread starter Thread starter Michael Persaud
  • Start date Start date
M

Michael Persaud

Hello,

I am trying to insert into a SQL2000 dbase some records

i am havinf some difficulty with the code below:

Dim Reports

If CboReportsTo.Text.ToString > "" Then

Reports = CboReportsTo.Text.ToString

Else

Reports = ""

End If

Dim str As String = "insert into Jobtitle(JobTitle,JobDescription,ReportsTo)
values('" _

& txtTitle.Text & "','" & txtDescription.Text & "','" & Reports & "')"

MsgBox(str)

Dim sqlcom As New SqlCommand(str, sqlcon)

'sqlcom.CommandText = str

sqlcon.Open()

sqlcom.ExecuteNonQuery() ' this line

sqlcon.Close()



I set a connection string as follows in the class of the vb form;

Dim strC As String = "integrated security=sspi;Data source=to-is1;initial
catalog=HRO"

Dim sqlcon As SqlConnection = New SqlConnection(strC)



I cant get the record inserted; sqlexception, system error



thanks



Michael
 
Look at exception.message. It will give you more details. It would also be
nice to know what line is throwing the exception.

Also:

Dim Reports --> You should declare the type.

CboReportsTo.Text.ToString --> it is a string, no need for ToString

If CboReportsTo.Text.ToString > "" Then --> CboReportsTo.Length > 0

Chris
 
Back
Top