protected void button1_Click(object sender, EventArgs e)
{
SqlConnection con = null;
con = new SqlConnection(@"Data Source=(LocalDB)\v11.0 ; AttachDbFilename=C:\Users\Bhawna\Documents\Visual Studio 2012\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Database2.mdf;Integrated Security=True ; User ID=sa ; Password=123");
try
{
con.Open();
String Sqlquery = (" Insert INTO adb (Studentid) values (@S)");
SqlCommand sqlupdate = new SqlCommand(Sqlquery, con);
sqlupdate.Parameters.AddWithValue("@S",Convert.ToInt16(textBox1.Text));
//sqlupdate.Parameters.Add(new SqlParameter("@S", SqlDbType.VarChar, 50)).Value = textBox1.Text;
int result= sqlupdate.ExecuteNonQuery();
label1.Text =result.ToString() + " Row is inserted into table";
textBox1.Text = "Connection Established";
con.Close();
}
catch (Exception ex)
{
label1.Text ="outer catch: " + ex.Message;
textBox1.Text = " Not Connected";
}}
bhawnanarang91
0
Newbie Poster
Recommended Answers
Jump to PostAny error messages? What doesn't work.
Please don't just give us a code chunk.
Jump to PostIn your INSERT statement adb is table not database, (studentid) is column an @s is the value you are inserting
the general expreseion goes like this INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
All 7 Replies
Mike Askew
131
Veteran Poster
Featured Poster
bhawnanarang91
0
Newbie Poster
Michael27
29
Newbie Poster
bhawnanarang91
0
Newbie Poster
nakor77
21
Junior Poster in Training
bhawnanarang91
0
Newbie Poster
Momerath
1,327
Nearly a Senior Poster
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.