harpal Singh harpal Singh - 1 year ago 192
ASP.NET (C#) Question

Insert data using SqlDataAdapter

I am very confuse with following code .This is also inserting data into table with insert in Stored procedure, even this has not executenonquery(),executescalar() or adapter.insert like methods...
then how it is possible

public DataSet GetDataSet(string spName, System.Collections.Hashtable hst)
cmd.CommandTimeout = 220;
con = new SqlConnection();
cmd = new SqlCommand();
con.ConnectionString = constr;
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName;
if (hst != null)
if (hst.Count > 0)
AttachParameters(cmd, hst);
DataSet dataset = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
return dataset;


Answer Source

This method just Retrieve the data u wanted and storing it into your dataset adapter.Fill(dataset); this part is used to fill your dataset with the data u populate out.

So as to pass to your stored procedure so technically your stored procedure is doing the insert not this.In your stored procedure u should have a insert statement

If the stored procedure is in your database stored procedure folder u do not need to use adapter as it will run internally to retrieve the results

something like this

INSERT INTO msdb.dbo.db(db) VALUES (@dbdata)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download