C#组合框数据未在sql server数据库表中更新 [英] C# combo box data is not updating in sql server database table
问题描述
我创建了一个包含7个表的sql数据库。
bankacc
cashpay
客户
opening_balance
付款
receievedchq
提款
并为客户,银行和付款创建三种表格。
bankacc表:bankid,bankname,branchname,accname,accountno
客户表:custid,custname,custadd,tpno
付款表:paymentid ,paymentdate,custname,description,chqno,duedate,accname,amount
付款表单有两个用于custname和accname的组合框
custname组合应该连接到:customer table custname
accname combo应该连接到:bankacc table accname
并希望通过这一切记录到数据库中的付款表。我是c#的新手。任何人都可以帮忙编码。
i've created a sql database contains 7 tables.
bankacc
cashpay
customer
opening_balance
payment
receievedchq
withdrawal
and also create three forms for customer, bankacc and payments.
bankacc table : bankid,bankname,branchname,accname,accountno
customer table : custid,custname,custadd,tpno
payments table : paymentid,paymentdate,custname,description,chqno,duedate,accname,amount
in payments forms there are two combo boxes for custname and accname
custname combo should be connected to : customer table custname
accname combo should be connected to : bankacc table accname
and want to pass this all record to payments table in database. I am new to c#. can anyone help with coding.
推荐答案
您可以将组合框项目传递到您的数据库。
使用:custnam.SelectedItem.toString()
和帐户名:accname.SelectedItem.toString()
如果仍然无法理解。粘贴您的代码,以便我们了解您的问题。
You can take Pass the combobox item to your database.
use : custnam.SelectedItem.toString()
and for account name : accname.SelectedItem.toString()
if still not able to understand. paste your code so we can understand your problem.
用于客户名称使用
custname.SelectedValue.ToString();
和账户名称使用
accname.SelectedValue.ToString();
SelectedValue 属性将为您提供ComboBox控件中当前选定的值。这适用于 WinForms 。
WebForms
使用 SelectedItem 属性代替 SelectedValue 。
for Customer Name use
custname.SelectedValue.ToString();
and for Account Name use
accname.SelectedValue.ToString();
SelectedValue property will give you the currently selected value from the ComboBox control. This will work in WinForms.
For WebForms
use SelectedItem property in place of SelectedValue.
您可以使用 SelectedItem.Text 或 SelectedItem.ToString()
示例
you can use SelectedItem.Text or SelectedItem.ToString()
example
ddlcustname.SelectedItem.Text or ddlcustname.SelectedItem.ToString()
和
and
ddlaccname.SelectedItem.Text or ddlaccname.SelectedItem.ToString()
一个建议
如果你的 custname 和 accname 是可编辑的,那么你应该在PaymentTable中使用CustId和AccId来保证数据准确性
如果适用则忽略在您的情况下
One Suggestion
If your custname and accname are editable then you should take CustId and AccId in PaymentTable for data accuracy
Ignore if it's applicable in your case
这篇关于C#组合框数据未在sql server数据库表中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!