如何在按钮点击上显示下一条记录 [英] how to display next record on button click

查看:111
本文介绍了如何在按钮点击上显示下一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();

              }



          }

推荐答案





查看此

Hi ,

Check this
this.BindingContext[dt].Position += 1;





最好的问候

M.Mitwalli



Best Regards
M.Mitwalli


我认为您患有短期记忆丧失问题。这是一个重新发布...

您之前使用相同的代码发布了相同的问题,用户为您提供了正确的解决方案此处 [ ^ ] .....



但你又发了同样的问题。我可以保证解决方案是正确的。只需检查数据库是否包含所选标准的数据,并从这里 [ ^ ]

逐行调试代码并检查每个对象是否都分配了预期值?检查异常是否有..
I think you suffer from a short term memory loss problem. This is a repost...
You have posted the same question with same code earlier and users have provided you with correct solutions here[^].....

But you posted the same question again. I can guarantee that the solutions are correct. Just check if the database has the data for the selected criteria and learn some basics of ado.net from here[^]
Debug the code line by line and check if every object is assigned its expected value? Check the exception if any..


你的代码应该是这样的。

Your code should be like this.
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!!!!!


这篇关于如何在按钮点击上显示下一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆