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.
Quote:
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)
{
}
}
}
Re: I Know I Am Doing Something Wrong Code Wise.
tblAddresses is not the same as Addresses