[英]Textbox Autorefresh after insert data to database
i have a textbox in C# and a insertbutton , i have allready show Max+1 in textbox from my databse column ItemId 我在C#中有一个文本框和一个insertbutton,我已经从我的数据库列ItemId中的文本框中全部显示了Max + 1
OleDbDataAdapter _adapter = new OleDbDataAdapter("SELECT MAX(ItemId)+1 FROM TableItem", con); DataTable _datatable = new DataTable(); _adapter.Fill(_datatable); textBoxInsert.Text = _datatable.Rows[0][0].ToString();
now textbox show successfully may data but when i have going to insert to data insert successfully and refresh grid and can not auto refresh text box which i have show max+1 i have following insertion command 现在文本框成功显示了可能的数据,但是当我要插入到数据中时,成功插入并刷新网格并且无法自动刷新文本框,我已经显示了max + 1我有以下插入命令
> OleDbDataAdapter adp3 = new OleDbDataAdapter("INSERT INTO
> TableItem(ITEMID,ITEMNAME,UNITID,CATEGORYID,ITEMSTATUS,SUPPLIERID)VALUES('"+textBoxInsert.Text+"','"+textBoxItem.Text+"','"+comboBoxUnitId.Text+"','"+comboBoxCategory.Text+"','"+textBoxStatus.Text+"','"+comboBoxSupplier.Text+"')",
> con);
> adp3.SelectCommand.ExecuteNonQuery();
>
> autorelode();//Call Autoload Method
>
> OleDbDataAdapter _adapter = new OleDbDataAdapter("SELECT MAX(ItemId)+1 FROM TableItem", con);
> DataTable _datatable = new DataTable();
> _adapter.Fill(_datatable);
> textBoxInsert.Text = _datatable.Rows[0][0].ToString();
but can not auto refresh my data in textbox. 但无法自动刷新文本框中的数据。
you can create method then call the method in insert button 您可以创建方法,然后在插入按钮中调用该方法
private void auto() { OleDbDataAdapter adp= new OleDbDataAdapter("SELECT MAX(ChallanNo)+1 FROM TablePurchase", con); DataTable dt = new DataTable(); adp.Fill(dt); ChallanNo.Text = dt.Rows[0][0].ToString(); con.Close(); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.