|
-
Jul 4th, 2003, 10:48 AM
#1
Thread Starter
Member
datagrid update
hi there, im using the following code to load data into a datagrid and update it, but the update part isnt working fine, any ideas?
Dim conn As New OleDbConnection(connection_str)
conn.Open()
sql_str = "select * from num"
Dim objCommand As New OleDbCommand(sql_str, conn)
Dim DS As New DataSet()
data_adapter = New OleDbDataAdapter(objCommand)
data_adapter.Fill(ds, "to")
DataGrid1.DataSource = ds.Tables("to")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim ds As New DataSet()
If ds.HasChanges() Then
MsgBox("yes")
End If
the error msg is :
An unhandled exception of type 'System.NullReferenceException' occurred in datagridexple.exe
Additional information: Object reference not set to an instance of an object.
thank you.
There is,we are,abou il zoulouf,mijana w mal3ona
-
Jul 4th, 2003, 11:55 AM
#2
Frenzied Member
Your code has some problems:
1-I dont see any need for 'conn.Open()' in second line.
2- What you mean by update, if you mean to update the database, i see no update code.
3-In click event 'ds' is not decalred, so you face Nullreference excpetion.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jul 4th, 2003, 12:18 PM
#3
Thread Starter
Member
im getting the error in the click code:
if ds.haschanges() ----
ds is allready declared in form_load,
im checking if the dataset has changes then im gonna update, and the error is keep on showing!
thank u.
There is,we are,abou il zoulouf,mijana w mal3ona
-
Jul 4th, 2003, 12:29 PM
#4
Frenzied Member
I think you need to learn more about the scope of variables. The variable not declared as public in a private Sub will remain private to that sub and not accecible by others.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jul 4th, 2003, 12:30 PM
#5
Sleep mode
Then ds is not accessible from the click event . Better you declare it public .
-
Jul 4th, 2003, 12:52 PM
#6
Thread Starter
Member
thank u all for yr replies, it just was stupid from me not to realize it!
cld u tell tell me whats the code behind updating the datagrid on the button_click event. ill make sure i buy a dot net book but in the mean while i cld really use any available help.
thank you
There is,we are,abou il zoulouf,mijana w mal3ona
-
Jul 4th, 2003, 01:03 PM
#7
Frenzied Member
There are some ways to perform an update. But all of those need an update/insert command. Just as a quciky first declare your adapter and dataset public. then use a command builder to build the adapters update, delete, and insert commands. then u can update yourt database using data_adapter.Update(ds, "to")
Search this forum for command builder and you will find how to use it. Use the search below the posts not the one in the above blue band.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jul 4th, 2003, 01:04 PM
#8
if you have updated your access table / dataset then just doing this :
VB Code:
data_adapter.Fill(ds, "to")'/// fill with the updated stuff
DataGrid1.DataSource = ds.Tables("to")
should update the stuff in the datagrid.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jul 4th, 2003, 01:05 PM
#9
Frenzied Member
Oh my bad, I thought he is talking of updating the database.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|