Seach

how to insert into table in c#

first import System.data.sqlclient;
 SqlConnection c = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\aspprojects\insertion\WebSite1\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
        try
        {
            c.Open();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = c;
            cmd.CommandText = "insert into student values('"+TextBox1.Text+"','"+Convert.ToInt32(TextBox2.Text)+"','"+TextBox3.Text+"')";
            cmd.ExecuteNonQuery();
            clear_();
        }
        catch (Exception e)
        {
            Response.Write(e.Message);
        }
        finally
        {
            c.Close();
        }

No comments: