inserting data thru forms
-
hey i am developing a web application using asp.net, but coding in C#. i need to insert into my database (sql server 2000/access). how shud i do it. i have two textboxes.. watever the user enters in it, it shud be added in a particular table.
Kunal Piyush
-
hey i am developing a web application using asp.net, but coding in C#. i need to insert into my database (sql server 2000/access). how shud i do it. i have two textboxes.. watever the user enters in it, it shud be added in a particular table.
Kunal Piyush
-
You take the values and run the query through an SQLCommand Object, that's the simplest solution...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
i coded a bit.. but now sql database i showing an error if i keep the field "Username" as a primary key. firstly the data is entered in a very ad-hoc fashion.. there is a row empty at the top...data entered in between two rows which are already filled with data.. and if i delete some data,then i get the error as "Another user has modified the contents of the table,the database row ur modifying no longer exists in the database....... violation of PRIMARY KEY constraint...." THE CODE:- try { SqlConnection conn = new SqlConnection("server=(local);" + "database=path;" + "connection timeout=3;" + "Trusted_Connection=yes;" + "Integrated Security=true;" + "user id=sa;" + "password="); conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "Insert into login(Username,Password) values('"+uname.Text+"','"+pass.Text+"')" ; SqlDataReader dread = cmd.ExecuteReader(); if (dread.Read()) { failed.Text = "Could not add the user"; } else { Response.Redirect("success.aspx"); } conn.Close(); } catch(Exception kp) { failed.Text=kp.Message; } }
Kunal Piyush