Insert data into database using Asp.net

Posted by Unknown On Friday, 8 March 2013 0 comments
First of all you have to create sql connection with the database...
            For this see the following link

http://aspdotneteasy.blogspot.in/2013/03/aspnet-sql-connection.html#more

Now you have to define one button and textboxes as per your field in .aspx file. . .

now write the following code in button click event...

in my .aspx file 2 textbox, 2 dropdownlist box,radio button and one image control is there. . .



Following code is about the .aspx.cs file
protected void Button1_Click(object sender, EventArgs e)
    {
               con.open();
              SqlCommand cmd = new SqlCommand("insert into client_list values('" + name.Text + "','" + add.Text + "','" + mob.Text + "','" + dt1.Rows[0]["sid"].ToString() + "','" + dt1.Rows[0]["cityid"].ToString() + "','" + gi + "','" + img.ImageUrl + "')", con);
                cmd.ExecuteNonQuery();
}

in between the + sign you have to defin your control vale

e.g      +TextBox1.Tex+  etc...

0 comments:

Post a Comment