i need to insert data into sql server table emp through
textboxes txtname and txtsalary using c# code. Please help

Answer Posted / suresh

open the Sqlconnection and write the connection string dere
and take one sqldata Adapter and also take one datatable
write the following code.

sqlconnection con=new sqlconnection("server=.; user Id=sa;
Password=sa123; Database=emp");
sqlDataAdapter da;
DataTable dt;

In Button Click Event you write this code

da=new sqlDataAdapter("insert into Emp(EmpID,Ename) values
('"+textbox1.Text+"','"+textbox2.Text+"'",con);
dt=new DataTable();
da.Fill(dt);


That's it you entered the Data into SQL Server

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we make a Static Constructor Parameterized? Give Reason with your answer

758


What language do desktop applications use?

676


What is the difference between a function and a method?

695


What is a dll in c#?

636


Can we change static variable value in c#?

663


Define MSIL, and how does it works? Why our developers need an appreciation of it if at all?

722


What is the difference between list and array in c#?

651


Why do we use void in c#?

653


Can abstract class have constructor?

668


What are the methods in c#?

699


What are accessors?

709


Can you inherit multiple classes in c#?

700


Explain the clr triggers?

711


What is the difference between inheritance and abstract class?

644


What is the CTS, and how does it relate to the CLS?

742