Combobox值到数据库sql

编程入门 行业动态 更新时间:2024-10-24 20:24:18
本文介绍了Combobox值到数据库sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我正在尝试使用3层业务逻辑将组合框值传递给数据库。目前,我的表单页面如下所示:

Hello, I am trying to pass combobox value to a database, using a 3 tier business logic. Currently my form page looks like this:

private void Savebtn_Click(object sender, EventArgs e) { try { SaveRole(tbroledesc.Text, /*combobox selected item gets passed here*/); MessageBox.Show("Club role saved successfully"); } catch (Exception er) { MessageBox.Show(er.Message.ToString()); } } public void SaveRole(string RoleDesc, /*combobox selecteditem*/) { ClubRoles cr = new ClubRoles(); RoleCreatedBy = Convert.ToInt32(lstcreatedby.SelectedItem); cr.insertingclubroles(RoleDesc, RoleCreatedBy); gettingclubroles(); //refresh the list }

我如何将组合框中选择的内容作为参数传递给它? 我正在填充组合框这个:

How can I pass what ever is selected in the combobox drop down as the parameter? I am filling the combobox like this:

private void loadclient() { DataSet dsloadclient; dsloadclient = new ClubRoles().createdby(); //need fix duplicate values DataTable dt = dsloadclient.Tables[0].DefaultView.ToTable(true, "ClientName", "ClientId"); lstcreatedby.DataSource = dt; lstcreatedby.DisplayMember = "ClientName"; lstcreatedby.ValueMember = "ClientId"; }

任何帮助将不胜感激。 谢谢。

Any help will be appreciated. Thanks.

推荐答案

像这样修改代码................. 。 获取你应该只使用SelectedValue的值因为你只在值字段中绑定ClientId Modify your code like this way.................. to get the values you should use only SelectedValue because you bind the ClientId in value field only public void SaveRole(string RoleDesc, /*combobox selecteditem*/) { ClubRoles cr = new ClubRoles(); if (lstcreatedby.SelectedIndex > 0) { RoleCreatedBy = Convert.ToInt32(lstcreatedby.SelectedValue); cr.insertingclubroles(RoleDesc, RoleCreatedBy); } gettingclubroles(); //refresh the list }

private void loadclient() { DataSet dsloadclient; dsloadclient = new ClubRoles().createdby(); //need fix duplicate values DataTable dt = dsloadclient.Tables[0].DefaultView.ToTable(true, "ClientName", "ClientId"); lstcreatedby.DataSource = dt; lstcreatedby.DataTextField= "ClientName"; lstcreatedby.DataValueField= "ClientId"; }

您可以使用intellisense学到很多东西。 要获取所选项目,请使用SelectedItem属性 msdn.microsoft/en-us/library/system.windows.formsbobox.selecteditem(v = vs.110) .aspx [ ^ ] You can learn a lot by using intellisense. To get the selected item, use the SelectedItem property, msdn.microsoft/en-us/library/system.windows.formsbobox.selecteditem(v=vs.110).aspx[^]

更多推荐

Combobox值到数据库sql

本文发布于:2023-11-10 01:05:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573941.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   Combobox   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!