Inserting data to an access database

UberDan

Member
Joined
Nov 27, 2005
Messages
18
Programming Experience
Beginner
Ok, I'm writing a program that's meant to interact with an access database containing student information. I have a form that retrieves and displays the information using the following code:

VB.NET:
OleDbDataAdapter1.SelectCommand.CommandText = "select * from StudentTable where StudentNumber = '" & txtFind.Text & "'"
OleDbDataAdapter1.Fill(DsStudent1)

txtNumber.Text = Convert.ToString(DsStudent1.Tables(0).Rows(0)("StudentNumber"))
txtName.Text = Convert.ToString(DsStudent1.Tables(0).Rows(0)("StudentName"))
txtPhone.Text = Convert.ToString(DsStudent1.Tables(0).Rows(0)("PhoneNumber"))
txtEnrollDate.Text = Convert.ToString(DsStudent1.Tables(0).Rows(0)("EnrollDate"))
txtLoanAmount.Text = Convert.ToString(DsStudent1.Tables(0).Rows(0)("StudentLoan")
Unfortunately, my professor neglected to tell me how exactly to UPDATE the information back into the database once it's been edited.

I also have a second form that has the same text boxes and a button called btnAdd that's meant to add a record to the database. I assume this is done with the same method used to update a record. If anyone can explain the process to me briefly I would be much obliged.
 
What you need is a SQL UPDATE and a INSERT command these, and a third DELETE command are action queries and are responsible for making changes to yout database. The UPDATE command can go like this...

VB.NET:
Dim cmd as new oledbcommand("UPDATE tablename SET  Studentname = ? , StudentNumber = ? 'And so on for all your column names. WHERE Primarykey = ?"
Then Add the parameters to your oledbcommand..

VB.NET:
Cmd.parameters.add("@Studentname", oledbtype.varwchar,255,"StudentNAme".value = The value you want to update with.
Continue adding the paramerters until you have one for every question mark in your query, They must be added in the same order as they appear in your query. Goolge SQL UPDATE and you'll get a whole host of info. If you get stuck post back.
 
Back
Top