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
Difference between overriding and overloading?
What does a switch do?
What is the difference between an htmlinputcheckbox control and an htmlinputradiobutton control?
What is the recommended approach for asp.net mvc to globally intercept exceptions? What other functionality can be implemented with the approach? : Asp.Net MVC
Is post back in asp.net?
What is state management in asp.net with example?
What is the difference between the response.write() and response.output.write() methods?
Can anyone please tell me that the question posted on this website are Sufficient for the interview with 2+ year experience in .net
What is caching in asp.net?
What’s the use of “GLOBAL.ASAX” file?
Which adapter should you use, if you want to get the data from an access database?
Briefly describe the role of global.asax?
What is the difference between dynamic SGA and static SGA?
What is the difference between equals() and == in c#?
How does asp.net work?