0

Hello Frens,
I tried to update change made in database shown DataGridView1 of Visual Studio 2008 with the following codes. But an error message comes as "Object reference not set to an instance of an object".

Public Class Form1
Dim cmd As Odbc.OdbcCommand
Dim adp As Odbc.OdbcDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Db1DataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Db1DataSet.Table1)
'TODO: This line of code loads data into the 'Db1DataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Db1DataSet.Table1)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Update records using a Command Builder
' The variable i gives the number of records updated
Dim cmdbuilder As New Odbc.OdbcCommandBuilder(adp)
Dim i As Integer
Try
i = adp.Update(Db1DataSet, "Table1")
MsgBox("Records Updated= " & i)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

Plz help me

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by jackVB
0

Using CommandBuilder it should be:

Dim adp As New Odbc.OdbcDataAdapter("SELECT * FROM tablename WHERE PrimaryKey = '" & Texbox1.Tex &"'", yourconnection)
Dim ds As New DataSet
Dim cmdbuilder As New Odbc.OdbcCommandBuilder(adp)
adp.Fill(ds)

ds.Tables(0).Rows(0).Item("Field1") = Me.Textbox2.Text
'do the rest

adp.Update(ds)
0

Thanks,

May i know your name. I am Nasir Ahmed. I impressed with your quote "Remember your creator before you die" than the code. I rather request to remember Our Creator all the time.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.