How to Insert a TextBox value in to Sql database using C#
coding?
Answers were Sorted based on User's Feedback
Answer / anand
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=anand\\sqlexpress.
initial catalog=Database1;integrated security=sspi;";
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = "Insert into
usr(firstname,lastname,dob,phno,email,Address,state,bgroup)
Values('" + firstname.Text + "','" + lastname.Text + "'," +
dob.Text + "," + phno.Text + ",'" + email.Text + "','" +
Address.Text + "','" + state.Text + "','" + bgroup.Text + "')";
myCommand.Connection = con;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
Is This Answer Correct ? | 5 Yes | 4 No |
Answer / balakumar
string strconn = @"Data Source=localhost;
Initial Catalog=Bala;
Trusted_Connection=yes;";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string insertcommand = "insert into Employee
values('" + TextBox1.Text + "','" + TextBox2.Text + "','" +
TextBox3.Text + "')";
SqlCommand cmd = new SqlCommand(insertcommand, conn);
cmd.ExecuteNonQuery();
conn.Close();
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / surendra
How to Insert two TextBoxs values in to one column sql database using C# coding
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / mmm
almost all the posted answers above are correct(85%).
Is This Answer Correct ? | 3 Yes | 4 No |
Answer / jeevananth
try
{
SqlConnecion cn=new SqlConnection("Data
source=.;database=Studentdetail;uid=sa;pwd=sa");
SqlCommand cmd=new SqlCommand();
cn.Open();
string qry;
qry="insert into Table values('"+ TextBox1.Text +"','"+
TextBox2.Text +"')";
cmd=new(qry,cn);
cmd.cmd.ExecuteNonQuery();
cn.Close();
}
catch(Exception ex)
{
Responce.Write(ex.Message.ToString());
}
Is This Answer Correct ? | 0 Yes | 6 No |
What is asp.net and ado net?
Differentiate between structure and class.
What Is ASPNET_WP.exe? What Is The Use Of It? In Which Place Inproc Session Stored ? Explain Session State ?
2 Answers Phoenix Technologies,
What is the difference between debug and release?
Difference between overriding and overloading?
How we can force all the validation controls to run?
Compare and contrast between inline and code behind - which one is best?
What is a postback url?
Fetch one page value to another page without using state-managment ?
What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
What are all the ways to find out types of objects?
what is diffrent between asp & asp.net