SQL insert

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
 
C

Chris

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top