harpal Singh harpal Singh - 3 months ago 31
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;
con.Open();
if (hst != null)
if (hst.Count > 0)
AttachParameters(cmd, hst);
DataSet dataset = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(dataset);
con.Close();
return dataset;

}

Answer

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)

Comments