Results 1 to 2 of 2

Thread: I Know I Am Doing Something Wrong Code Wise.

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    53

    Thumbs up I Know I Am Doing Something Wrong Code Wise.

    I keep getting the error below even though my table name is Addresses. I am getting a connection to server and all.
    Invalid object name 'tblAddresses'.
    Here is code
    Code:
            System.Data.SqlClient.SqlConnection con;
            DataSet ds1;
            System.Data.SqlClient.SqlDataAdapter da;
    
            int MaxRows = 0;
            int inc = 0;
    
            private void Form1_Load(object sender, EventArgs e)
            {
                con = new System.Data.SqlClient.SqlConnection();
                ds1=new DataSet();
    
                con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\sql2k5\\Inventory_Control_Retail.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
    
                con.Open();
                string sql = "Select * from tblAddresses";
                MessageBox.Show("f");
                da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
                da.Fill(ds1, "Addresses");
                NavigateRecords();
                MaxRows = ds1.Tables["Addresses"].Rows.Count;
                con.Close();
    
                con.Dispose();
    
            }
            private void NavigateRecords()
            {
                DataRow dRow = ds1.Tables["Addresses"].Rows[inc];
    
                txtBoxID.Text = dRow.ItemArray.GetValue(0).ToString();
                txtBoxFirstName.Text = dRow.ItemArray.GetValue(1).ToString();
                txtBoxLastName.Text = dRow.ItemArray.GetValue(2).ToString();
                txtBoxJobTitle.Text = dRow.ItemArray.GetValue(3).ToString();
    
            }
    
            private void btnNext_Click(object sender, EventArgs e)
            {
                if (inc != MaxRows - 1)
                {
                    inc++;
                    NavigateRecords();
                }
                else
                {
                    MessageBox.Show("No More Employees");
                }
            }
    
            private void tabPage1_Click(object sender, EventArgs e)
            {
    
            }
        }
    }

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: I Know I Am Doing Something Wrong Code Wise.

    tblAddresses is not the same as Addresses

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width