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

Can we set master page as a start page?

549


What are app services?

534


What are the namespace classes used in asp.net mvc? : asp.net mvc

552


What are the built-in objects in asp.net?

560


What is the function of new view engine in asp.net? : asp.net mvc

549






What is the difference between mvc (model-view-controller) and mvp (model-view-presenter)? : asp.net mvc

546


Explain MVC model binders?

601


Explain what is event bubbling?

578


What parameters can you pass in the url of the api?

664


What is request and response in asp.net?

514


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

532


What is the parent class of all web server control?

539


How to unit test Web API?

711


Where can I get the details on migration of existing projects using various technologies to asp.net?

523


Why session is used in asp.net?

533