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

How to retrieve user name in case of Window Authentication?

262


What are the differences between application object and session object?

485


Can you explain why it is useful to use mvc instead of webforms? : asp.net mvc

527


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?

557


How many web config files can be created for an application?

439






How many validators do ASP.NET have?

595


What is ascx?

519


Can you set the session out time manually?

366


Explain the Session state management options available with ASP.NET?

558


What is the purpose of master page?

510


How tooltip is set through code-behind in ASP.NET?

565


What are the different types of sessions in asp.net? Name them?

666


what is meant by sitemapnode ?

1487


What are sharepoint pages?

485


Explain Apache web servers ? How can you get ASP.NET running in Apache web servers - why should you do this?

502