ALLInterview.com :: Home Page      
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   Errors
   Refer this Site  Refer This Site to Your Friends  Site Map  Contact Us      
   
 
Categories >> Software >> Microsoft Related >> ASP.NET
 


 

 
Question
How to Insert a TextBox value in to Sql database using C#
coding?
 Question Submitted By :: ASP.NET
  I also faced this Question!!      
Answer Posted By  
 Answers were Sorted based on User's Feedback
Answer
# 1
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 ?    189 Yes 82 No
chandra shaker
 
Answer
# 2
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 ?    157 Yes 55 No
v.vijayakumar
 
 
Answer
# 3
insert into emp(empname) values('"+textbox1.Text+"'); 

Is This Answer Correct ?    157 Yes 61 No
sona
 
Answer
# 4
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 ?    143 Yes 56 No
premkumar.m
 
Answer
# 5
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 ?    111 Yes 33 No
digital
 
Answer
# 6
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 ?    62 Yes 26 No
jegan
 
Answer
# 7
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 ?    49 Yes 23 No
ramachandraprabu
 
Answer
# 8
sqlcommand cmd = new sqlcommand("insert into address values
(@textbox1.text,@textbox2.text)",connectionstring); 

Is This Answer Correct ?    61 Yes 37 No
pksutha
 
Answer
# 9
sqlcommand cmd = new sqlcommand("insert into address values
('"+ textbox1.text +"', "+ textbox2.text +")",
connectionstring); 

Is This Answer Correct ?    64 Yes 41 No
suthasyed
 
Answer
# 10
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 ?    50 Yes 33 No
pranitha
 

 
 
 
Other ASP.NET Interview Questions
 
  Question Asked @ Answers
 
What is role manager work in web.config? how to restrict perticular pages from the users using the role manager? infosys 1
what is the cursor wipro 1
what is abstract class and method..   2
How do I debug an ASP.NET application that wasn't written with Visual Studio.NET and that doesn't use code-behind?   1
What are the major differences between asp.net1.1 and asp.net 2.0? cts 8
What are the data types is possible to store in session? and can we store dataset in session? emids 4
How can we read a columnised text data in ASP.Net C#? Columnised means my data is stored in a text file and I have numeric data or string data in this file. For ex. If I am searching for the data of gender and I know that gender data is stored at column 32 in text file. How can I get this data in ASP.Net page. Thanks for help in advance.   2
What is the difference between a session object and cache object citigroup 2
How many types is controls is there in Asp.Net?If it means what are types of custom controls?Explain about user controls,Web server controls,Hrml server controls? cap-gemini 1
Suppose you display a data having 200 records in a datagrid. Then you edit 100 records of them. Now when you will press update button,all 100 records should be updated in single shot rather than reading every record and updating. How to do it? wipro 4
What is the transport protocol you use to call a Web service?   2
Whats MSIL, and why should my developers need an appreciation of it if at all?   2
 
For more ASP.NET Interview Questions Click Here