hi i m new c# and this is my very 1st project ,here i want to add or view data and this is the code i have used.everything works fine but i cant navigate through records properly,i m working with 2 tables i.e BankMaster and BranchMaster
private void branchmaster_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data source=SID\\SQLEXPRESS;Initial Catalog=Taj - Hotel Management;Integrated Security=True";
ds = new DataSet();
da = new SqlDataAdapter("select * from BranchMaster", con);
da.Fill(ds, "BranchMaster");
SqlCommandBuilder bldr = new SqlCommandBuilder(da);
da1 = new SqlDataAdapter("select * from BankMaster", con);
da1.Fill(ds,"BankMaster");
SqlCommandBuilder cbldr = new SqlCommandBuilder(da1);
bmgr = this.BindingContext[ds, "BranchMaster"];
txt_BranchID.DataBindings.Add("Text", ds, "BranchMaster.BranchID");
txt_BankID.DataBindings.Add("Text", ds, "BankMaster.BankID");
txt_BranchName.DataBindings.Add("Text",ds,"BranchMaster.BranchName");
txt_BranchPhoneNo.DataBindings.Add("Text",ds,"BranchMaster.BranchPhoneNo");
txt_BranchContactPerson.DataBindings.Add("Text", ds, "BranchMaster.BranchContactPerson");
txt_BranchAdd.DataBindings.Add("Text", ds, "BranchMaster.BranchAdd");
cbox_BankName.DataSource = ds;
cbox_BankName.DisplayMember = "BankMaster.BankName";
txt_BankID.Enabled = false;
txt_BranchID.Enabled = false;
}
private void btn_add_Click(object sender, EventArgs e)
{
txt_BranchAdd.Text = "";
txt_BranchContactPerson.Text = "";
txt_BranchPhoneNo.Text = "";
txt_BranchName.Text = "";
int ctr, len;
string codeval;
dt = ds.Tables["BranchMaster"];
len = dt.Rows.Count - 1;
dr = dt.Rows[len];
code = dr["BranchID"].ToString();
codeval = code.Substring(1, 3);
ctr = Convert.ToInt32(codeval);
if ((ctr >= 1) && (ctr < 9))
{
ctr = ctr + 1;
txt_BranchID.Text = "000" + ctr;
}
else if ((ctr >= 9) && (ctr < 99))
{
ctr = ctr + 1;
txt_BranchID.Text = "0" + ctr;
}
else if ((ctr >= 99) && (ctr < 999))
{
ctr = ctr + 1;
txt_BranchID.Text = "0" + ctr;
}
}
private void btn_save_Click(object sender, EventArgs e)
{
dt = ds.Tables["BranchMaster"];
dr = dt.NewRow();
dr[0] = txt_BranchID.Text;
dr[1] = txt_BankID.Text;
dr[2] = txt_BranchName.Text;
dr[3] = txt_BranchAdd.Text;
dr[4] = txt_BranchPhoneNo.Text;
dr[5] = txt_BranchContactPerson.Text;
dt.Rows.Add(dr);
da.Update(ds, "BranchMaster");
txt_BranchID.Text = Convert.ToString(dr[0]);
this.da.Fill(ds, "BranchMaster");
}
private void btn_next_Click(object sender, EventArgs e)
{
bmgr.Position += 1;
}
private void btn_prev_Click(object sender, EventArgs e)
{
bmgr.Position -= 1;
}