I made an online application to store employees information in MS SQL,I used Disconnected model and I made my class for "DataSet configuration" and call method in it in The "Form_Load" event. This is the class
public static string constr = ConfigurationManager.ConnectionStrings["cnn1"].ConnectionString;
public static DataSet GetDataSet(string stored_name, string table_name, params SqlParameter[] prmarr)
{
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(stored_name, con);
foreach (SqlParameter prm in prmarr)
{
cmd.Parameters.Add(prm);
}
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, table_name);
return ds;
I set the Connection string in "Web.Config"
Till now all things is ok but when I insert data to "DataSet" Error message appear
Object reference not set to an instance of an object.
Line 42: DataRow drnew = ds.Tables["x"].NewRow();
this is the code I Type in insert Button
DataRow drnew = ds.Tables["x"].NewRow();
drnew["First_Name"] = txtfname.Text;
drnew["Last_Name"] = txtlname.Text;
drnew["Country"] = drpboxcoun.SelectedValue;
drnew["Email"] = txtemail.Text;
drnew["Experience_Years"] = txtexper.Text;
drnew["Current_Salary"] = txtcursal.Text;
drnew["Expected_Salary"] = txtexpsal.Text;
ds.Tables["x"].Rows.Add(drnew);
I check the types compatible with fields in my database. so where is the problem !!