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
Can we set master page as a start page?
What are app services?
What are the namespace classes used in asp.net mvc? : asp.net mvc
What are the built-in objects in asp.net?
What is the function of new view engine in asp.net? : asp.net mvc
What is the difference between mvc (model-view-controller) and mvp (model-view-presenter)? : asp.net mvc
Explain MVC model binders?
Explain what is event bubbling?
What parameters can you pass in the url of the api?
What is request and response in asp.net?
Explain program to call the js function when the change is being made in the dropdown list made in asp.net mvc? : asp.net mvc
What is the parent class of all web server control?
How to unit test Web API?
Where can I get the details on migration of existing projects using various technologies to asp.net?
Why session is used in asp.net?