|
| Form data to MySQL database |
 |
Thu, 28 Feb 2008 20:21:58 +000 |
can someone help me out, i'm a complete novice and i'm finding MSDNs help files
not very useful.
Anyway could someone please tell me how i can submit my form data to a database
called Users.mdf
|
| Post Reply
|
| Re: Form data to MySQL database |
 |
Thu, 28 Feb 2008 21:51:29 +000 |
Hello,
If you are using c# you could try something like this:
1 private void cmdNew_Click(object sender, EventArgs e)
2 {
3 string insertSQL;
4 insertSQL = "INSERT INTO Users (Fname, Lname) VALUES
(@Fname, @Lname)";
5 OleDbConnection con = OleDbConnection(conncetionstring);
6 OleDbCommand cmd = OleDbCommand(insertSQL, con);
7 8 cmd.Parameters.AddWithValue("@Fname",
txtFname.Text);
9 cmd.Parameters.AddWithValue("@Lname",
txtLname.Text);
10 11 try12 {
13 con.Open();
14 cmd.ExecuteNonQuery;
15 }
16 17 catch (Exception err)
18 {
19 blError.Text = err.Message;
20 }
21 22 finally23 {
24 con.Close();
25 }
26 }
In this example you have 2 textboxes names txtFname and txtLname. a Button
named cmdNew and a label named lblError so can see if there is an error while
trying to connect to the database.
The button should have an onClick event named cmdNew_Click
On the place of connectionString you put something like
"Provider=MySQLProv;Data Source=mydb;User
Id=myUsername;Password=myPassword" For more information on connection
strings see http://www.connectionstrings.com/?carrier=mysql
I hope this will help you, if you have any more questions feel free to ask
them.
Arnold
|
| Post Reply
|
|
|
|
|
|
|
|
|
|