如何在按钮单击的数据网格视图中显示sql数据库的next,last和previos记录? [英] how to diplay next, last and previos record of sql database in datagrid view on button click..?

查看:79
本文介绍了如何在按钮单击的数据网格视图中显示sql数据库的next,last和previos记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlCommand cmd = new SqlCommand("select i.Installment_Amount,i.Paid_Amount, i.Remaining_Amount,i.Due_Date,i.Fine, i.Amount_recieved,i.Transaction_Date, i.Transaction_no,i.Loan_id, i.Paid_with_fine,c.Customer_CNIC from Installment_Payment i, Customer c where exists(select i.Loan_id,c.Loan_id, l.Loan_id,c.Customer_CNIC from Loan l,Customer c, Installment_Payment i where i.Loan_id=c.Loan_id and c.Customer_CNIC=''" + cbocnic1.Text + "-" + cbocnic2.Text + "-" + cbocnic3.Text + "'')", cn);
             //MessageBox.Show(query1);
             cmd.CommandType = CommandType.Text;
             da = new SqlDataAdapter(cmd);
             dt = new DataTable();
             da.Fill(dt);
             if (dt.Rows.Count == 0)
             {



                 MessageBox.Show("The Record for Customer''" + cbocnic1.Text + "-" + cbocnic2.Text + "-" + cbocnic3.Text + "''Does not Exist!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 cbocnic1.SelectAll();
                 cbocnic1.Focus();

             }
             else
             {
                 for (i = 0; i <= dt.Rows.Count - 1; i++)
                 {
                     int newRowIndex = ins.dataGridView1.Rows.Add();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Loan_id"].Value = dt.Rows[i]["Loan_id"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Transaction_no"].Value = dt.Rows[i]["Transaction_no"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Installment_Amount"].Value = dt.Rows[i]["Installment_Amount"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Due_Date"].Value = dt.Rows[i]["Due_Date"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Transaction_Date"].Value = dt.Rows[i]["Transaction_Date"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Fine"].Value = dt.Rows[i]["Fine"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Paid_with_fine"].Value = dt.Rows[i]["Paid_with_fine"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Amount_recieved"].Value = dt.Rows[i]["Amount_recieved"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Paid_Amount"].Value = dt.Rows[i]["Paid_Amount"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Remaining_Amount"].Value = dt.Rows[i]["Remaining_Amount"].ToString();
                     ins.dataGridView1.Rows[newRowIndex].Cells["Customer_CNIC"].Value = dt.Rows[i]["Customer_CNIC"].ToString();
                 }
                 this.Hide();

                 ins.ShowDialog();
                 this.Close();

             }

推荐答案

查看这篇文章,提供的信息比你提出的要多一些但是学习新东西没有坏处:添加,编辑,并使用分页在DataGridView中删除 [ ^ ]
Check this article out, has a little more information than you asked for but there is no harm in learning something new: Add, Edit, and Delete in DataGridView with Paging[^]


这篇关于如何在按钮单击的数据网格视图中显示sql数据库的next,last和previos记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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