Results 1 to 4 of 4

Thread: Error message when compiling SQL and C# project

  1. #1
    Join Date
    Nov 2008
    Posts
    159

    Error message when compiling SQL and C# project

    Hey recently I have begun with my SQL and C# project. I have a table that have a row called "log" and a table also called as "log". I then try and make it so that when I press a button with the name of the log should get a message box with history. Below you can see the code and error message. Someone who knows. please help me to get it to work?

    Code:
    private void logToolStripMenuItem_Click (object sender, EventArgs e) 
    { 
    string transID; 
    datatable_log = new Bluetooth_Sender_v._1._4.data_blue.logDataTable(); 
    datatable_log = dataadapter_log.GetDataBy(transID); 
    if (datatable_log.Rows.Count == 0) 
    { 
    MessageBox.Show ("The Log is empty"); 
    } 
    else 
    { 
    string log_alert; 
    foreach (DataRow row in datatable_log.Rows) 
    { 
    log_alert = row ["log"]. ToString (); 
    } 
    MessageBox.Show (log_alert); 
    } 
    }
    Error Message:
    Error CS0165: Use of unassigned local variable 'transID'
    Error CS0165: Use of unassigned local variable 'log_alert'

  2. #2
    Join Date
    May 2008
    Posts
    945

    Re: Error message when compiling SQL and C# project

    "use of unassigned local variable" error message clearly indicates that you are using variables that has not been assigned any value. In your case, the compiler is unable to find any values for "transID" and "log_alert" variables.

  3. #3
    Join Date
    Nov 2008
    Posts
    159

    Re: Error message when compiling SQL and C# project

    All right thanks but whatever it does not work either. So if someone could help me with this then it would be great.

  4. #4
    Join Date
    Feb 2008
    Posts
    194

    Re: Error message when compiling SQL and C# project

    I think the following will work. It is probably also appropriate to add the line breaks after each line of the log that is added to logMsg.

    Good luck

    Code:
    private void logToolStripMenuItem_Click (object sender, EventArgs e) 
    {
    // Declare variables 
    String transId = String.Empty; // Transaction Id that we want to show 
    String logMsg = String.Empty; // Message 
    datatable_log = new Bluetooth_Sender_v._1._4.data_blue.logDataTable ();
    
    // Retrieve data 
    /* 
    * This assumes that 'dataadapter_log' is instansiert in class 'logToolStripMenuItem_Click' 
    * Are in, and that it has a valid connection string. 
    */ 
    datatable_log = dataadapter_log.GetDataBy (transId); 
    
    // Processes and view data 
    if (datatable_log.Count == 0) 
    {
    logMsg = "The log is empty."; 
    }
    else 
    {
    foreach (DataRow row in datatable_log.Rows)
    { 
    if (row ["log"]! = null) 
    logMsg += (String) row ["log"]; 
    }
    }
    MessageBox.Show (logMsg); 
    }

Similar Threads

  1. STDOLE2.TLB error message when opening Project
    By Fatmeer in forum Microsoft Project
    Replies: 14
    Last Post: 02-12-2013, 11:29 AM
  2. MS Office Project has stopped working error message
    By Frragrant in forum Microsoft Project
    Replies: 14
    Last Post: 15-04-2012, 02:47 PM
  3. Replies: 5
    Last Post: 13-01-2012, 05:20 PM
  4. Error compiling easyapache
    By Who is it in forum Software Development
    Replies: 6
    Last Post: 16-06-2010, 04:13 AM
  5. Replies: 4
    Last Post: 25-01-2010, 10:08 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,882,750.90088 seconds with 17 queries