How to Insert a TextBox value in to Sql database using C#
coding?
Answer Posted / digital
SqlCommand CmdSql = new SqlCommand("INSERT INTO
Customers(FirstName,Surname,Address,City,Postcode,PhoneNumber)
Values
(@FirstName,@Surname,@Address,@City,@Postcode,@PhoneNumber)", conn);
conn.Open();
CmdSql.Parameters.AddWithValue("@FirstName", FirstName);
CmdSql.Parameters.AddWithValue("@Surname", Surname);
CmdSql.Parameters.AddWithValue("@Address", Address);
CmdSql.Parameters.AddWithValue("@City", City);
CmdSql.Parameters.AddWithValue("@Postcode", Postcode);
CmdSql.Parameters.AddWithValue("@PhoneNumber",
PhoneNumber);
CmdSql.ExecuteNonQuery();
conn.Close();
//all @values are names of the variables the text value is
stored as (you could also enter txtFirstName.Text etc.)
//conn = connection name (which should be declared before
the page_load
Is This Answer Correct ? | 113 Yes | 35 No |
Post New Answer View All Answers
How to retrieve user name in case of Window Authentication?
What are the differences between application object and session object?
Can you explain why it is useful to use mvc instead of webforms? : asp.net mvc
What is side-by-side execution? Can two applications, one using a private assembly and other using a shared assembly, be stated as side-by-side executables?
How many web config files can be created for an application?
How many validators do ASP.NET have?
What is ascx?
Can you set the session out time manually?
Explain the Session state management options available with ASP.NET?
What is the purpose of master page?
How tooltip is set through code-behind in ASP.NET?
What are the different types of sessions in asp.net? Name them?
what is meant by sitemapnode ?
What are sharepoint pages?
Explain Apache web servers ? How can you get ASP.NET running in Apache web servers - why should you do this?