Insert SQL command with vb.net

how do i make insert command ?

Page 1 of 1

2 Replies - 52424 Views - Last Post: 12 May 2005 - 07:24 AM Rate Topic: ***** 1 Votes

#1 fei_hyblade  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 11
  • Joined: 10-May 05

Insert SQL command with vb.net

Posted 11 May 2005 - 11:58 PM

ok,i write a code for sql insert in a button like this :

Dim stringAdd As String = "Insert into Maintenance_Table (hardware_desc) values ('"& desc & "')



Dim objcommand As New SqlClient.SqlCommand(stringAdd, New _
SqlClient.SqlConnection("workstation id=max;packet size=4096;integrated security=SSPI;initial catalog=nosys;persist security info=False"))

objcommand.Connection.Open()
objcommand.ExecuteNonQuery()
objcommand.Connection.Close()

objcommand.Dispose()
objcommand = Nothing

and it gives me an error at objcommand.executenonquery().do you know why?? please help :).btw,is there any weakness using those pre made data component (data adapter,connection,etc) from windows form? this far i made the program with pure coding :(.

This post has been edited by fei_hyblade: 12 May 2005 - 12:01 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Insert SQL command with vb.net

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Insert SQL command with vb.net

Posted 12 May 2005 - 05:30 AM

What error does it give you? As an fyi, your SQL string is not completely enlcosed in quotes...it should look something like this:
Dim stringAdd As String = "Insert into Maintenance_Table (hardware_desc) values ('"& desc & "')"


Was This Post Helpful? 0
  • +
  • -

#3 fei_hyblade  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 11
  • Joined: 10-May 05

Re: Insert SQL command with vb.net

Posted 12 May 2005 - 07:24 AM

got it fixed :),the error is in my database,i forgot that i declare all of them the "not null" constraint,while i'm testing of inserting only two columns -_-.that figures,solved the problem,the syntax works perfectly ^^
Was This Post Helpful? 1

Page 1 of 1