如何将ComboBox选择的值插入数据库特定列? [英] How to insert ComboBox selected value into the database specific column?

查看:249
本文介绍了如何将ComboBox选择的值插入数据库特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想根据Combobox选择值将借方和贷方价值插入数据库表。我的ComboBox由Cr组成。博士项目和数据库表格列是Id,Name,Debit和Credit。当我从ComboBox中选择Debit并输入金额1000(在文本框中)时,表Debit列应显示为1000Dr,Credit列应为null如果我从ComboBox中选择Credit并输入金额500,则Credit列应显示为500Cr。(借方栏应为空)。



这是示例

 Id名称借记贷方
1 Ram 1000Dr。 NULL
2 Ravan NULL 500Cr。



如何为此编写代码?



谢谢提前。

解决方案

正如我在评论中建议你的过去的问题 [ ^ ],你必须写出正确的数据结构。



信用卡和借记卡应存储在同一列中!如果用户选择博士,请保存负数值。这就是全部!



sql命令可能如下所示:

  INSERT   INTO  TableName(Credit_Debit) VALUES  @creditDebit 





点击此链接了解如何调用此查询: SqlParameterCollection.AddWithValue方法 [ ^


Hi,

I want to insert debit and credit values into the database table based on Combobox Selected Values.My ComboBox consists of Cr. and Dr. items and the Database table columns are Id,Name,Debit and Credit.When I select Debit from ComboBox and enter amount 1000 (in textbox) then the table Debit column should display as 1000Dr and the Credit column should be null like wise If I select Credit from ComboBox and enter amount 500 then the Credit column should display as 500Cr.(Debit column should be null).

Here is Example

Id       Name      Debit           Credit
 1        Ram         1000Dr.        NULL
 2        Ravan       NULL           500Cr.


How to write code for this?

Thanks in advance.

解决方案

As i suggested in the comments to your past question[^], you have to write proper data structure.

Credit and debit should be stored in the same column! If user chooses Dr., save negative numeric value. That's all!

A sql command might look like:

INSERT INTO TableName (Credit_Debit) VALUES(@creditDebit)



Follow this link to find out how to call this query: SqlParameterCollection.AddWithValue Method[^]


这篇关于如何将ComboBox选择的值插入数据库特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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