364,088 Members | 5440 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

VB.net MS SQL inserts but NOT Updating

fiaworkz
P: 1
I've been working for this for more than an hour
Hope someone helps me.
Here's my code


Expand|Select|Wrap|Line Numbers
  1. Try
  2.  
  3.             Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\LBHdb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
  4.             con.Open()
  5.             cmd.Connection = con
  6.  
  7.  
  8.  
  9.  
  10.  
  11.             'cmd.CommandText = "INSERT INTO tblTires(brandname, treadname, size, purchasecost, unitprice) VALUES('" & cboCompanyname.Text & "','" & txtproductname.Text & "','" & txtsize.Text & "' ,'" & txtpurchaseprice.Text & "','" & txtpriceperunit.Text & "'  )"
  12.             cmd.CommandText = "INSERT INTO tblTires (brandname, treadname, size, purchasecost,unitprice) values(@bN,@tN,@sz,@pc,@up)"
  13.             cmd.Parameters.Add("@bN", Data.SqlDbType.Text).Value = cboCompanyname.Text
  14.             cmd.Parameters.Add("@tN", Data.SqlDbType.Text).Value = txtproductname.Text
  15.             cmd.Parameters.Add("@sz", Data.SqlDbType.Text).Value = txtsize.Text
  16.             cmd.Parameters.Add("@pc", Data.SqlDbType.Decimal).Value = txtpurchaseprice.Text
  17.             cmd.Parameters.Add("@up", Data.SqlDbType.Decimal).Value = txtpriceperunit.Text
  18.             cmd.Connection = con
  19.             Dim ds As New DataSet
  20.             Dim da As New SqlDataAdapter
  21.             Dim sql As String = "SELECT * FROM tblTires "
  22.             da.SelectCommand = New SqlCommand(sql, con)
  23.             da.InsertCommand = cmd
  24.  
  25.             da.Fill(ds, "tblTires")
  26.             da.Update(ds, "tblTires")
  27.  
  28.  
  29.  
  30.  
  31.             cmd.ExecuteNonQuery()
  32.             con.Close()
  33.             MsgBox("Tire Information has been added", MsgBoxStyle.Information, "Success")
  34.             cleartxtboxt()
  35.         Catch ex As Exception
  36.             Throw New Exception(ex.Message)
  37.         End Try
  38.  
  39.  


Don't ask the error cause' there's none.
The problem is it does not Update the records in its database when it's stopped, or run again.
Jan 23 '12 #1
Share this Question
Share on Google+
1 Reply


ranjaniVinsInfo
P: 34
Say clearly about your problem. thanks
Jan 23 '12 #2

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework insert sql update