I have a main form which has an Add Teacher button and an Add subject button which directs them to their respective forms.The add teacher button works perfectly fine but when i click the add subject button it shows error: Cannot find table at position 1.I have been following the same procedure in add subject button as i did in add teacher button .Also I first added tbl_teachers table and then tbl_subjects table in my database ,so technically tbl_teachers should have index 0 right?Also when i click the Data Source section I only see it has only tbl_teachers.How do I update the data source? Thanks in advance.
try
{
SubjectConnect = new DatabaseConnection();
conString = Properties.Settings.Default.teachersConnectionString;
SubjectConnect.connection_string = conString;
SubjectConnect.sql = Properties.Settings.Default.SQL2;
ds = SubjectConnect.GetConnection;
Maxrows = ds.Tables[1].Rows.Count;
}
catch (Exception err)
{
MessageBox.Show(err.Message,"error");
}
class DatabaseConnection
{
private string sql_string;
private string strCon;
SqlDataAdapter da_1;
public string sql
{
set { sql_string = value; }
}
public string connection_string
{
set { strCon = value; }
}
public DataSet GetConnection
{
get { return MyDataset(); }
}
private DataSet MyDataset()
{
SqlConnection con = new SqlConnection(strCon);
con.Open();
da_1 = new SqlDataAdapter(sql_string, con);
DataSet dat_set = new DataSet();
da_1.Fill(dat_set,"Table_data_1");
con.Close();
return dat_set;
}
public void UpdateDatabase(DataSet ds)
{
SqlCommandBuilder cb = new SqlCommandBuilder(da_1);
cb.DataAdapter.Update(ds.Tables[0]);
}
}