Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How to check if the Dataset has records ?

1008


What is XML serialization

1062


Can datareader hold data from multiple tables?

1180


Why edit is not possible in repeater?

951


Explain how can we load multiple tables in to dataset?

943


Explain how to call the sql commands asynchronously in ado.net version 2.0?

931


Which one of the objects is a high-level abstraction of the connection and command objects in ado.net?

1151


Compare Data Reader & Dataset in ado.net?

1001


What is the namespaces being used to access oracle database?

1082


What is an ADO.Net?

992


What is difference between datareader and dataadapter?

1051


Define executenonquery?

917


Can we create Synonymns in MS Acess,My Sql Server,Sql Server? But iam we can create in oracle!

2142


What do you know about ADO.NET's objects and methods?

979


can we create synonymn in ms access,sql server,my sql if so explain me with example

2088