本文介绍了如何在按钮点击上显示下一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void Display_record()
{
string query = "Select * from ACCOUNTS where Account_number ='" + comboBox1.SelectedItem + "'";
//MessageBox.Show(query);
da1 = new SqlDataAdapter(query, cn);
dt1 = new DataTable();
da1.Fill(dt1);
int i = dt1.Rows.Count-1;
//for (int i = 0; i <= dt1.Rows.Count - 1; i++)
comboBox1.Text = (dt1.Rows[i]["Account_number"].ToString());
txtcustomername.Text = (dt1.Rows[i]["Name"].ToString());
txtoccupation.Text = (dt1.Rows[i]["Occupation"].ToString());
txtfathername.Text = (dt1.Rows[i]["Father_name"].ToString());
txthusbandname.Text = (dt1.Rows[i]["Husband_name"].ToString());
txtcustomercnic.Text = (dt1.Rows[i]["Customer_CNIC"].ToString());
txtinitialdeposit.Text = (dt1.Rows[i]["Initial_deposit"].ToString());
dateTimePicker1.Value = (Convert.ToDateTime(dt1.Rows[i]["Date"]));
txtpostaladdress.Text = (dt1.Rows[i]["Postal_address"].ToString());
txtemail.Text = (dt1.Rows[i]["Mail"].ToString());
txtmobilenumber.Text = (dt1.Rows[i]["Mobile"].ToString());
}
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
if (i < dt1.Rows.Count - 1)
{
i = i + 1;
Display_record();
}
}
推荐答案
this.BindingContext[dt].Position += 1;
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
int recordindex =0;
string query = "Select * from ACCOUNTS where Account_number ='" + comboBox1.SelectedItem + "'";
//MessageBox.Show(query);
da1 = new SqlDataAdapter(query, cn);
dt1 = new DataTable();
da1.Fill(dt1);
public void Display_record(int i)
{
comboBox1.Text = (dt1.Rows[i]["Account_number"].ToString());
txtcustomername.Text = (dt1.Rows[i]["Name"].ToString());
txtoccupation.Text = (dt1.Rows[i]["Occupation"].ToString());
txtfathername.Text = (dt1.Rows[i]["Father_name"].ToString());
txthusbandname.Text = (dt1.Rows[i]["Husband_name"].ToString());
txtcustomercnic.Text = (dt1.Rows[i]["Customer_CNIC"].ToString());
txtinitialdeposit.Text = (dt1.Rows[i]["Initial_deposit"].ToString());
dateTimePicker1.Value = (Convert.ToDateTime(dt1.Rows[i]["Date"]));
txtpostaladdress.Text = (dt1.Rows[i]["Postal_address"].ToString());
txtemail.Text = (dt1.Rows[i]["Mail"].ToString());
txtmobilenumber.Text = (dt1.Rows[i]["Mobile"].ToString());
}
private void button1_Click(object sender, EventArgs e)
{
if (recordindex >= dt1.Rows.Count-1)
{
//show end of record message.
}
elseif (recordindex == 0)
{
Display_record(recordindex);
}
else
{
recordindex++;
Display_record(recordindex);
}
}
All The Best !!!!!
All The Best!!!!!
这篇关于如何在按钮点击上显示下一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!