need your help, I am following an online tutorial of creating an SQL database
http://www.homeandlearn.co.uk/csharp/csharp_s12p9.html
I have followed the code provided to the dot, but i have am en-countering an error where i keep get the object reference is of set of an instance of an object in C#
The code that visual studio is flagging up is
cb.DataAdapter.Update(ds.Tables[0]);
I have no idea, what the error means, by reading up the error its something to do with a null reference. Could anyone be able to tell me what the error is and how to fix it.
This is my class file (http://pastebin.com/38zW6Zk7):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EmployeeDatabse
{
class DatabaseConnection
{
private string sql_string;
private string strCon;
System.Data.SqlClient.SqlDataAdapter da_1;
public string sql
{
set { sql_string = value; }
}
public string connection_string
{
set { strCon = value; }
}
public System.Data.DataSet GetConnection
{
get { return MyDataSet(); }
}
public void UpdateDatabase(System.Data.DataSet ds)
{
System.Data.SqlClient.SqlCommandBuilder cb = new System.Data.SqlClient.SqlCommandBuilder(da_1);
cb.DataAdapter.Update(ds.Tables[0]);
}
private System.Data.DataSet MyDataSet()
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(strCon);
con.Open();
System.Data.SqlClient.SqlDataAdapter da_1 = new System.Data.SqlClient.SqlDataAdapter(sql_string, con);
System.Data.DataSet dat_set = new System.Data.DataSet();
da_1.Fill(dat_set, "Table_data_1");
con.Close();
return dat_set;
}
}
}