如何从数据库中获取当前值? [英] How Do I Fetch Current Value From Data Base?

查看:87
本文介绍了如何从数据库中获取当前值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i我正在以窗口形式C#.i制作帐单申请。取两个数据集并拖放两个表以便在报表视图上打印数据。然后我创建一个报表并绑定数据然后在新表格和拖放报表查看器控件之后设置这些数据。当我运行此应用程序时,单击提交按钮当前账单数据插入到数据库中。我想在报表上打印最后一个账单ID的详细信息。![输入图像说明这里] [1]





当我点击提交按钮时,这个账单没有全部细节正确地插入到数据库中。

c#中的保存和打印按钮代码:



  private   void  button3_Click_1( object  sender,EventArgs e)
{
.Close();

Form2 f2 = new Form2();
f2.Show();

}



点击保存并打印下面的表格打开。![在此处输入图像说明] [2]。 />
按钮代码点击:



  private   void  button1_Click( object  sender,EventArgs e)
{
da = new SqlDataAdapter( 通过billId DESC从Bill_Detail订单中选择billId,cn);
DataSet ds = new DataSet();
da.Fill(ds);
int id = Convert.ToInt32(ds.Tables [ 0 ]。行[ 0 ] [ 0 ]。ToString());
textBox1.Text = id.ToString();
<跨度类= 代码关键字>此 .Customer_detailTableAdapter.Fill(<跨度类= 代码关键字>此 .DataSet1.Customer_detail,Convert.ToInt32(textBox1的。文本));
<跨度类= 代码关键字>此 .Bill_DetailTableAdapter.Fill(<跨度类= 代码关键字>此 .DataSet2.Bill_Detail,Convert.ToInt32(textBox1的。文本));
reportViewer1.LocalReport.Refresh();
this .reportViewer1.RefreshReport();
}



i已经尝试但它不起作用。我可以在报告查看器中获取当前Bill no的详细信息吗?







这是我的报告查看器。这个表格没有正确收取账单但没有打印账单没有数据。

解决方案

如果它是主键,您可以选择max(billid),也可以在上面的查询中选择您已写入的前1个账单ID。


DA =新的SqlDataAdapter( 选择最高(BILLID)从Bill_Detail为了通过BILLID DESC,CN);

使用 SCOPE_IDENTITY 以得到最后插入的行值< br $> b $ b

http://technet.microsoft.com /en-us/library/ms190315.aspx [ ^ ]

Hi,
i am making a bill application in window form C# .i take two data set and drag and drop two tables for printing data on report view.then i create a report and bind data with these data set then after new Form and drag and drop report viewer control.when i run this application on clicking submit button current bill's data inserted into data base.and i want to print this last bill id's detail on report.![enter image description here][1]


when i click on submit button this bill no's all detail inserted into data base properly.
Code of save and print button in c#:

private void button3_Click_1(object sender, EventArgs e)
       {
           this.Close();

           Form2 f2 = new Form2();
           f2.Show();

       }


after clicking save and print below form open.![enter image description here][2].
Code of Button click :

private void button1_Click(object sender, EventArgs e)
         {
	da = new SqlDataAdapter("select billId from Bill_Detail order by billId DESC", cn);
            DataSet ds = new DataSet();
            da.Fill(ds);            
            int id = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
             textBox1.Text = id.ToString();   
           this.Customer_detailTableAdapter.Fill(this.DataSet1.Customer_detail, Convert.ToInt32(textBox1.Text));             
             this.Bill_DetailTableAdapter.Fill(this.DataSet2.Bill_Detail, Convert.ToInt32(textBox1.Text));
             reportViewer1.LocalReport.Refresh();
             this.reportViewer1.RefreshReport();
         }


i have tried but it not works.how can i get current Bill no's detail in report viewer?



this is my report viewer from.this form takes bill no correctly but not print that bill no's data.

解决方案

well you can select max (billid) if it is a primary key and also you can select top 1 bill id in above query that you have write.


da = new SqlDataAdapter("select Max(billId) from Bill_Detail order by billId DESC", cn);


use scope_identity to get last inserted row value

http://technet.microsoft.com/en-us/library/ms190315.aspx[^]


这篇关于如何从数据库中获取当前值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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