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

Hey I am using asp.net mvc architecture. I creating one dropdownlist using <select id="State" name="State"></select> this is dynamic list.Its displaying properly. But in time of Edit.If i load a page dropdownlist is not displaying the item which is stored in table.

1 Answers  


What is difference between asp.net and asp.net mvc? : Asp.Net MVC

0 Answers  


What is WebService ?

8 Answers   Tanla Solutions, Yahoo,


Is asp.net is a programming language?

0 Answers  


What is the use of global.asax file?

0 Answers  






How does a content page differ from a master page?

0 Answers  


About dataset and data mining ?

1 Answers   Cognizant,


In my code i have 3 tables,i have to insert 3 tables data using single insert query so that i wrote transations in a sp.but what my problem is,in those 3 tables i have to include my empId from another table.when i'm passing values im getting error at this EmpId. how can i solve this error to execute insert query? plesae tell me the solution...

1 Answers  


What is the good practice to implement validations in aspx page?

0 Answers  


what is caching,session? when & what is used mostly in which situtations, how they r implemented in real time? tell with example?

1 Answers   Satyam,


Explain about the .NET framework?

0 Answers  


Can you please anyone explain in detailed Webservices concepts in Asp.net?

1 Answers  


Categories