Quote:
Originally Posted by ashukla
Hi All!
I want to update a record in my database but without using "update mytblname" query.
I am using following code
- sql = "select * from customer where id = " & Val(Me.id.Text)
-
-
-
Dim adapter As New SqlDataAdapter(sql, conn)
-
Dim builder As SqlCommandBuilder = New SqlCommandBuilder(adapter)
-
Dim ds1 As New DataSet("customer")
-
adapter.Fill(ds1, "customer")
-
Dim T As DataTable = ds1.Tables("customer")
-
Dim i As Integer
-
Dim row As DataRow
-
If T.Rows.Count = 0 Then
-
row = T.NewRow
-
Else
-
T.Rows(0).BeginEdit()
-
row = T.Rows(0)
-
row.BeginEdit()
-
End If
-
-
row("cname") = cname.Text
-
If addre.Text = "" Then addre.Text = "-"
-
row("address") = Me.addre.Text
-
If email.Text = "" Then email.Text = "-"
-
row("email") = email.Text
-
If ph.Text <> "" Then row("ph") = ph.Text
-
If cont.Text <> "" Then row("cont") = cont.Text
-
If other.Text <> "" Then row("other") = other.Text
-
If desi.Text <> "" Then row("desi") = desi.Text
-
row("zone") = Me.cmbzone.Text
-
If Val(Me.id.Text) = 0 Then
-
T.Rows.Add(row)
-
' Else
-
Else
-
T.Rows(0).EndEdit()
-
row.EndEdit()
-
End If
-
adapter.Update(ds1, "customer")
-
adapter.Dispose()Its giving me error.
-
WHat is problem with above code ?
Data is not getting updated to database/
Hi ,
As per my understanding you r going in the worng direction..
You wann to update the database Customer table from the table which is there in the ds1 dataset... Wright ?
If this is the case ..you need to use the ExecuteNonQuery() function of the DataAdapter..
Just have a look of Dataadapter.ExecuteNonQuery() and get your task done..
Please let me know about any clarification..
Thanks!