Click here to Skip to main content
15,894,291 members
Home / Discussions / C#
   

C#

 
GeneralRe: Interface using C# with Microsoft access database Pin
julyhaluna12-Oct-09 21:59
julyhaluna12-Oct-09 21:59 
GeneralRe: Interface using C# with Microsoft access database Pin
Calla12-Oct-09 22:18
Calla12-Oct-09 22:18 
QuestionPDF Files Pin
Pavan Navali12-Oct-09 19:02
Pavan Navali12-Oct-09 19:02 
AnswerRe: PDF Files Pin
Calla12-Oct-09 20:16
Calla12-Oct-09 20:16 
GeneralRe: PDF Files Pin
Pavan Navali9-Nov-09 20:07
Pavan Navali9-Nov-09 20:07 
AnswerRe: PDF Files Pin
0x3c012-Oct-09 20:38
0x3c012-Oct-09 20:38 
QuestionSQLDBCommandwrapper Pin
NICE TO MEET12-Oct-09 18:10
NICE TO MEET12-Oct-09 18:10 
QuestionSqlDataAdapter.Fill() error. Pin
snayler012-Oct-09 16:57
snayler012-Oct-09 16:57 
gday all.

i am getting this error:

Error: System.NullReferenceException: Object reference not set to an instance of an object.
at Keystore.FindKey.FindKey_Load(Object sender, EventArgs e) in C:\Users\Shane\Documents\Visual Studio 2008\Projects\Keystore1\Keystore1\FindKey.cs:line 89

when running this code:

private void FindKey_Load(object sender, EventArgs e)
       {
           SqlCommand command;
           DataTable dt;
           try
           {
               SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\KeyStore.mdf;Integrated Security=True;User Instance=True");
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex);
           }

           //Open the Connection

           try
           {
               con.Open();
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex);
           }

           // Query The Database
           try
           {
               command = new SqlCommand("SELECT * FROM Key", con);
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex);
               command = new SqlCommand("SELECT * FROM Key", con);
           }

           try
           {
               dt = new DataTable();
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex);
               dt = new DataTable();
           }

           try
           {
               SqlDataAdapter da = new SqlDataAdapter(command);
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex);
           }

           // Fill the Result In DataTable
           try
           {
               da.Fill(dt);
           }
           catch (Exception ex)
           {
              MessageBox.Show("Error: " + ex);
           }

           //Show it in the list
           try
           {
               for (int i = 0; i < dt.Rows.Count; i++)
               {
                   DataRow dRow = dt.Rows[i];
                   FoundKey newkey = new FoundKey(dRow);
                   lstMatchedKeys.Items.Add(newkey);
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex);
           }
               //Close the Connection
           try
           {
               con.Close();
           }
           catch (Exception ex)
           {
               MessageBox.Show("Error: " + ex);
           }

       }


sorry for all the try/catch's. been using them to try and pinpoint the error and the error message.

The error is coming from the "da.Fill(dt);" line. The rest runs ok.

Can anyone help me overcome this problem? =)
AnswerRe: SqlDataAdapter.Fill() error. Pin
PIEBALDconsult12-Oct-09 17:04
mvePIEBALDconsult12-Oct-09 17:04 
AnswerRe: SqlDataAdapter.Fill() error. Pin
Not Active12-Oct-09 17:04
mentorNot Active12-Oct-09 17:04 
GeneralRe: SqlDataAdapter.Fill() error. Pin
snayler012-Oct-09 17:12
snayler012-Oct-09 17:12 
GeneralRe: SqlDataAdapter.Fill() error. Pin
snayler012-Oct-09 17:25
snayler012-Oct-09 17:25 
GeneralRe: SqlDataAdapter.Fill() error. Pin
Mycroft Holmes12-Oct-09 17:29
professionalMycroft Holmes12-Oct-09 17:29 
GeneralRe: SqlDataAdapter.Fill() error. Pin
snayler012-Oct-09 17:35
snayler012-Oct-09 17:35 
GeneralRe: SqlDataAdapter.Fill() error. Pin
Mycroft Holmes12-Oct-09 17:44
professionalMycroft Holmes12-Oct-09 17:44 
QuestionIn XNA, how to recognize mouse gestures? Pin
hoyomi12-Oct-09 14:23
hoyomi12-Oct-09 14:23 
AnswerRe: In XNA, how to recognize mouse gestures? Pin
benjymous12-Oct-09 22:29
benjymous12-Oct-09 22:29 
GeneralRe: In XNA, how to recognize mouse gestures? Pin
hoyomi13-Oct-09 3:37
hoyomi13-Oct-09 3:37 
GeneralRe: In XNA, how to recognize mouse gestures? Pin
benjymous14-Oct-09 2:46
benjymous14-Oct-09 2:46 
QuestionHow can I send Ctrl-C using Telnet to a host machine? Pin
zenlc200012-Oct-09 14:19
zenlc200012-Oct-09 14:19 
AnswerRe: How can I send Ctrl-C using Telnet to a host machine? Pin
PIEBALDconsult12-Oct-09 15:18
mvePIEBALDconsult12-Oct-09 15:18 
GeneralRe: How can I send Ctrl-C using Telnet to a host machine? Pin
zenlc200012-Oct-09 15:33
zenlc200012-Oct-09 15:33 
GeneralRe: How can I send Ctrl-C using Telnet to a host machine? Pin
PIEBALDconsult12-Oct-09 16:17
mvePIEBALDconsult12-Oct-09 16:17 
Questionxml Document Pin
arkiboys12-Oct-09 13:22
arkiboys12-Oct-09 13:22 
AnswerRe: xml Document Pin
Luc Pattyn12-Oct-09 13:40
sitebuilderLuc Pattyn12-Oct-09 13:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.