Object reference not set to an instance of an object.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Good morning all
would someone be kind enough to give me a little help?? I am completely new to C# and trying to teach myself, most of the time I can get through with looking at forums when I get a problem but
this one Im really stuck on. it to do with SQL data base.
I have created the database and table and assigned values to variables to just try and add a record
to the database, but for some reason the var dRow on the last line is set to Null, showing this when debugging and no matter what I try I cant assign it.
Please can anyone shed some light as to why


<span style="font-size:small <span style="font-size:small
System.Data.SqlServerCe.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlCeConnection<span style="font-size:small <span style="font-size:small con;
<span style="font-size:small <span style="font-size:small
System.Data.SqlServerCe.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlCeDataAdapter<span style="font-size:small <span style="font-size:small da;
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small DataSet<span style="font-size:small <span style="font-size:small ds1;
//******************************************<span style="font-size:small <span style="font-size:small
// this is on a form button_click from here
//*******************************************
<span style="font-size:small <span style="font-size:small
con = <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small System.Data.SqlServerCe.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlCeConnection<span style="font-size:small <span style="font-size:small ();
<span style="font-size:small <span style="font-size:small
con.ConnectionString = <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small &quot;Data Source=C:\Users\Eddie\Numbers.sdf&quot;;
<span style="font-size:small <span style="font-size:small
con.Open();
 // understand the line below may be wrong at the moment
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
string sql = <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small &quot;SELECT * from tbl_AllNumbers&quot;<span style="font-size:small <span style="font-size:small ; 
<span style="font-size:small <span style="font-size:small
da = <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small System.Data.SqlServerCe.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlCeDataAdapter<span style="font-size:small <span style="font-size:small (sql,
con);
<span style="font-size:small <span style="font-size:small
ds1 = <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small DataSet<span style="font-size:small <span style="font-size:small ();
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small
DataRow dRow = ds1.Tables[<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small &quot;Numbers&quot;<span style="font-size:small <span style="font-size:small ].NewRow();


thank you in advance

Eddie<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small


<span style="font-size:small <span style="font-size:small  
<span style="font-size:small <span style="font-size:small


<span style="font-size:small <span style="font-size:small
<span style="font-size:small <span style="font-size:small


<span style="font-size:small <span style="font-size:small
<span style="font-size:small <span style="font-size:small




<span style="font-size:small <span style="font-size:small  
<span style="font-size:small <span style="font-size:small


<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small


<span style="font-size:small <span style="font-size:small







<span style="font-size:small

<span style="font-size:small







<span style="font-size:small <span style="font-size:small
<span style="font-size:small <span style="font-size:small

View the full article
 
Back
Top