how to update tablein vb.net windows app

Posted by Shanky11 under VB.NET on 3/4/2013 | Points: 10 | Views : 1316 | Status : [Member] | Replies : 6
i have a table registration
column
userid
username
lastname
mobile
emailid
from a form through txtboxes i need to update this
how can i write coding of it
i writting this c0de is this ok?????????????????
"update registration set username='" + txtuserNameEdit.Text + "',lastname='" + txtLastName.Text + "',Mobile=" + txtMobile.Text + ",emailID='" + txtEmailID.Text + "' where ", sqlcon)




Responses

Posted by: Santhi on: 3/4/2013 [Member] Starter | Points: 25

Up
0
Down

Hi

What you have written is correct.

Thanks & Regards,
Santhi .V

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 3/4/2013 [Member] Starter | Points: 25

Up
0
Down
hi Santhi
but what about where condition
what i have to write in it

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhi on: 3/4/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

Pass the userid in the where condition.

Thanks & Regards,
Santhi .V

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 3/4/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
SqlConnection con = new SqlConnection(ConnectionString);
con.Open()
str = "Update employee set userid =@ userid ,username =@ username, lastname =@ lastname, mobile =@ mobile, emailid =@ emailid Where userid =@ userid "
com = new SqlCommand(str, con)
com.Parameters.AddWithValue("@userid ", txt_ userid.Text)
com.Parameters.AddWithValue("@username ", txt_ username.Text)
com.Parameters.AddWithValue("@lastname ", txt_ lastname.Text)
com.Parameters.AddWithValue("@emailid ", txt_ emailid.Text)
com.ExecuteNonQuery()
MessageBox.Show("Record Successfully Updated")
con.Close()


If this post helps you mark it as answer
Thanks

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 3/5/2013 [Member] Starter | Points: 25

Up
0
Down
hello satapriyank
it showing error ....................
must declare scalar variable
and one more thing i.e......
in where conditon u only declare @userid from where this value will come

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 3/5/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
str = "update employee set username='" + textBox2.Text + "',lastname='" + textBox3.Text + "',Mobile=" + textBox4.Text + ",emailID='" + textBox5.Text + "' where userid ='" + textBox1.Text.Trim() + "'";
com = new OleDbCommand(str, con);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Records Successfuly Updated");
con.Close()

If this post helps you mark it as answer
Thanks

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response