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


Please Help Members By Posting Answers For Below Questions

Fetch one page value to another page without using state-managment ?

523


What do you mean by serialize?

543


What is owin authentication?

512


Explain login control and form authentication.

550


Why would a company use an application service provider?

485






What is s2s tracking?

532


How can you handle unmanaged code exceptions in asp.net?

543


Is asp.net and .net the same?

506


Does asp.net still recognize the global.asa file?

547


Why asp.net mvc is better than asp.net? : Asp.Net MVC

493


Where viewstate value is stored in asp.net?

587


How to use push notification?

593


What is sta?

548


if i wanna deploy my asp.net project to the production server and situation is that i m still not compiled my project i have as-is on my development side now on production server we dont have a visual studio now what kind of settings i need to be to do in webconfig /machine.config file to deploy my project and in iis too....

1592


What is the difference between page-level caching and fragment caching?

520