A
AMG
Hi there,
This is probably a beginner doubt but am stuck and would appreciate any
help.
I have a method (LoadData) in my code-behind class that loads a table from
the database into a Dataset and then stores that in the Session.
Subequently I have a bunch of user interactions that alter that Dataset.
Finally I want to update the database (Proceed_Click) using the
SqlCommandBuilder and the SqlDataAdapter.
My problem is that when I call the update method, I get the following error
<error>
Object reference not set to an instance of an object.
</error>
I have declared the SqlAdapter as a private property of the code-behind
class and am intializing it within my "LoadData" method;
Here is the relevant code
<code>
public class part1 : System.Web.UI.Page
{
----------------
private SqlDataAdapter results_da;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack) // when the page first loads
{
// Get Data from Database
LoadData();
}
}
private void LoadData()
{
DataSet DelphiData = new DataSet();
LoadResults(DelphiData);
Session["DelphiData"] = DelphiData;
}
private void LoadResults(DataSet ds)
{
string user_name = Session["uName"].ToString();
SqlConnection myConnection = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnSt
r"].ToString());
string strSql = "Select * From test where UName='"+user_name;
results_da = new SqlDataAdapter(strSql, myConnection);
myConnection.Open();
results_da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
results_da.Fill(ds, "results");
myConnection.Close();
}
private void Proceed_Click(object sender, System.EventArgs e)
{
// update table
DataSet DelphiData = (DataSet)Session["DelphiData"];
SqlCommandBuilder resultsCommandBuilder = new
SqlCommandBuilder(results_da);
results_da.Update(DelphiData, "results");
debug_txt.Text = results_da.ToString();
}
}
</code>
Thanks in advance for any help
AMG
This is probably a beginner doubt but am stuck and would appreciate any
help.
I have a method (LoadData) in my code-behind class that loads a table from
the database into a Dataset and then stores that in the Session.
Subequently I have a bunch of user interactions that alter that Dataset.
Finally I want to update the database (Proceed_Click) using the
SqlCommandBuilder and the SqlDataAdapter.
My problem is that when I call the update method, I get the following error
<error>
Object reference not set to an instance of an object.
</error>
I have declared the SqlAdapter as a private property of the code-behind
class and am intializing it within my "LoadData" method;
Here is the relevant code
<code>
public class part1 : System.Web.UI.Page
{
----------------
private SqlDataAdapter results_da;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack) // when the page first loads
{
// Get Data from Database
LoadData();
}
}
private void LoadData()
{
DataSet DelphiData = new DataSet();
LoadResults(DelphiData);
Session["DelphiData"] = DelphiData;
}
private void LoadResults(DataSet ds)
{
string user_name = Session["uName"].ToString();
SqlConnection myConnection = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnSt
r"].ToString());
string strSql = "Select * From test where UName='"+user_name;
results_da = new SqlDataAdapter(strSql, myConnection);
myConnection.Open();
results_da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
results_da.Fill(ds, "results");
myConnection.Close();
}
private void Proceed_Click(object sender, System.EventArgs e)
{
// update table
DataSet DelphiData = (DataSet)Session["DelphiData"];
SqlCommandBuilder resultsCommandBuilder = new
SqlCommandBuilder(results_da);
results_da.Update(DelphiData, "results");
debug_txt.Text = results_da.ToString();
}
}
</code>
Thanks in advance for any help
AMG