Datagrid Update

jnash

Well-known member
Joined
Oct 20, 2006
Messages
111
Programming Experience
Beginner
VB.NET:
[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] txtmemberID_TextChanged([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] txtmemberID.TextChanged
temp = txtmemberID.Text
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] temp = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#800000]"Incorrect Customer Number"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] adapter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] MySqlDataAdapter = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] MySqlDataAdapter([/SIZE][SIZE=2][COLOR=#800000]"select rentalExpiry,rental1,rental2,rental3,rental4 from tblRental where memberNo ="[/COLOR][/SIZE][SIZE=2] & temp & [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2], TheConnection)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myDataTable [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataTable
adapter.Fill(myDataTable)
DGMember.DataSource = myDataTable
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]

This works fine but i want to edit the values in the database ! how to i click edit then update?

thanks


 
Read the DW2 link in my signature; it will tell you khow to do data access in 2.0, which will mean your button event handler code isnt littered with DB access stuff
 
You know.. that's somethign that irks me about university education. They install .NET 2.0 and then teach you the backwards, lame, poorly encapsulated ways of data access found in the '90s..

These lecturers need a kick up the backside, turning out graduates who write bad OO code simply because they were taught no different or forced to go along an old-school path. In some ways it's no better than teaching you to make everything static (shared) and writing the app procedurally.

Some may argue that it is "better" because you get an appreciation of what the database access layer does. I reckon that's balls; it's perfectly possible to teach the new methods and also teach (and examine on) how the methods work.


At the end of the day, the wizards merely write large amounts of code. That code is visible and usable as a teaching point. If your lecturer designs his form visually, but then forces you to write the DAL by hand, it's a hypocrisy; he should design the form by hand too (and I mean lay out every button, pixel perfect etc by typing the code that does it)


However, you do have to operate within the guidelines set by your course (just know that it's not the only way to do it and also, it's a bad way) so I would recommend that you use the wizard, look at the code it has generated. Read and understand it, and use it as a template to write your own DAL code.
And dont put the queries in the button handlers! (Look at the way the wizard does it. Work out what a tableadapter is etc)

(ps; show this post to your lecturer if you dare.. I'd be intrigued to see the response)


pps; it's "should have", not "should of" - I forget the name for such an error, but it arises from the way "should've" is pronounced. "should've" might sound like "should of" but it is most certainly a contraction of "should have"; try to avoid such horrendous grammatical mistakes - it doesnt look good and one day you might rely on your written english to ensure youre taken seriously.. :D
 
Personally I'd use a tableadapter to create your select, update, insert and delete code and call this...

Simple to update then!

i'm also interested in knowing how to do this... but im using visual basic.net 2003... i think it doesnt have table adapter here... so how can i do this?

thanks.
 
i'm also interested in knowing how to do this... but im using visual basic.net 2003... i think it doesnt have table adapter here... so how can i do this?

thanks.

Install VB Express 2005 (Free) or Visual Studio 2005 (Paid)
 
i think it doesnt have table adapter here... so how can i do this?

dataAdapters in 2003.....tableAdapters in 2005.

as Cjard suggested, if you can then bin 2003 and upgrade. Much much better (I've upgraded all my apps to .net 2.0 now)
 
Back
Top