i want 2 pass values(enterd in textbox)to table in sql
server without using stored procedure in c#.plz tell me
code with an example.
Answer Posted / ranjeet kumar panda
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
SQlDataAdapter da;
string sqlstr;
Connection String......
//using DataReader
sqlstr="insert into tablename(Colname) values
("+textBox1.Text+")";
if(con.state==ConnectionState.Open)
con.Close();
cmd.CommandText=sqlstr;
con.Opem();
cmd.ExecuteNonQuery();
//using DataSet
.........
........
da.Fill(ds,"tablename");
DataRow drw=ds.Tables[0].NewRow();
drw[0]=textBox1.Text;
ds.Table[0].Rows.Add(drw);
SqlCommandBuilder cb=new SqlCommandBuilder(da);
da.Update(ds,"tablename");
//Using LinqToSql (.Net 3.5)
DataContextName dc=new DataContextName();
//Lets a Control to bind the data
DataGridView1.DataSource=dc.GetTable<tablename>;
//create an object of class(i.e table)
tablename obj=new tablename();
obj.colname=textBox1.Text;
dc.tablenames.InsertOnSubmit(obj);//'s' in tablenames
//is essential
dc.SubmitChanges();
| Is This Answer Correct ? | 7 Yes | 3 No |
Post New Answer View All Answers
Define table relations?
Explain the various objects in dataset.
Difference between sqlcommand and sqlcommandbuilder?
How to pass values into a datatable?
What is the namespaces being used to access oracle database?
Which method in OLEDBAdapter is used to populate dataset with records?
how to create a quiz software using 4 options to answer and how to check with answers in the database and award marks....
What is a column variable?
What is ado rdo dao in visual basic?
Explain ODP.net
Does dapper use ado.net?
Explain how to bind the controls(best practice) comboboxes to the data in the dataset?
How to load multiple tables into a dataset?
How to retrieve the user id which is provided while windows authentication?
What is ado.net in vb net?