How to Insert a TextBox value in to Sql database using C#
coding?

Answers were Sorted based on User's Feedback



How to Insert a TextBox value in to Sql database using C# coding?..

Answer / chandra shaker

insert into emp(empname) values('"+textbox1.value+"')


If you use html cocntrol textbox1.Value
or
If you use Aso cocntrol textbox1.Text

Is This Answer Correct ?    192 Yes 84 No

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / v.vijayakumar

Syntax:
INSERT INTO table name(column name,column name,column
name)values(values,values,values);
Example:
INSERT INTO
employee(Name,emp_id,designation)values('"+textbox1.text+"',"+textbox2.text+",'"+textbox3.text+"');


..................if u use Html control we must use
textbox1.value ..if u use asp.net controls we have to use
textbox1.text........

Is This Answer Correct ?    160 Yes 56 No

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / sona

insert into emp(empname) values('"+textbox1.Text+"');

Is This Answer Correct ?    159 Yes 62 No

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / premkumar.m

in asp.net webform,

first assign namespace like using system.data.sqlclient;

insert coding

sqlcommand cmd = new sqlcommand("insert into address values
('"+ textbox1.text +"', "+ textbox2.text +")",
connectionstring);

note:

Is This Answer Correct ?    145 Yes 56 No

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / 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

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / jegan

SqlConnection con = new SqlConnection();
con.ConnectionString = "connection string(path)";
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into emp_detail values(' " + tb1.Text + " ',' " + tb2.Text + " ',' " + tb3.Text + " ')", con);
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}

Is This Answer Correct ?    66 Yes 26 No

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / ramachandraprabu

SqlConnection conn = new SqlConnection(strCon);
SqlCommand CmdSql = new SqlCommand("INSERT INTO Customers
(Firstname,Lastname,Address)Values('" + textbox1.Text
+ "', '"+textbox2.Test+"', '"+textbox3.Text+"')", conn);
CmdSql.ExecuteNonQuery();


\\If u use Html control we must use
textbox1.value
\\If u use asp.net controls we have to use
textbox1.text

Is This Answer Correct ?    51 Yes 23 No

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / pksutha

sqlcommand cmd = new sqlcommand("insert into address values
(@textbox1.text,@textbox2.text)",connectionstring);

Is This Answer Correct ?    63 Yes 37 No

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / suthasyed

sqlcommand cmd = new sqlcommand("insert into address values
('"+ textbox1.text +"', "+ textbox2.text +")",
connectionstring);

Is This Answer Correct ?    66 Yes 41 No

How to Insert a TextBox value in to Sql database using C# coding?..

Answer / pranitha

first assign namespace like using system.data.sqlclient;

SqlCommand cmd = new SqlCommand("insert into emp
(EmpName,EmployeeCode,Designation,Location)values('" +
TextBox1.Text + "','" + TextBox2.Text + "','" +
TextBox3.Text + "','" + TextBox4.Text + "')");

Is This Answer Correct ?    51 Yes 33 No

Post New Answer

More ASP.NET Interview Questions

Which keyword you should use for class not to extend? Which keyword to be used for making the class accessible within the assembly only what are the authentication mode of ASP.NET How will you call a JavaScript function using code-behind? How will you define the Session Timeout? What are the methods to validate client-side whether the input is a correct Date format? You want to write a log when ASP.NET application starts. Which is the best place to write that peice of code? What are the page load events and what is there order? What is the difference between abstract class and interface? What are the differences between DataSet and DataReader? What are the two properties other than DataSource, which is required to populate the Drop Down Menu? What is difference between String and StringBuilder Classes? What are differences between Custom control and User control?

1 Answers   Ignis Technologies,


How u refer webservices?

0 Answers   Microsoft,


what is a virtual class?

1 Answers   Patni,


What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?

1 Answers   Infosys, KPIT,


What methods are fired during the page load? Init()

0 Answers  






What is the difference between system.stringbuilder and system.string

0 Answers  


What is Difference between Callbacks and Postback in ASP.NET?

1 Answers   Patni,


What is clickid?

0 Answers  


What is source control?How to use in asp.net?

1 Answers  


In cache where dats is stored and how(file or object?)

2 Answers  


To display data in a Repeater control which template you provide?

0 Answers   Siebel,


How do you create a permanent cookie?

8 Answers   Siebel Systems,


Categories