这个很简单呀
int i;if(combbox1.selectitem == "操作员")
i = 0;
if(combbox1.selectitem == "系统管理员")
i = 1;然后把i写到数据库对应的字段就可以了
int i;if(combbox1.selectitem == "操作员")
i = 0;
if(combbox1.selectitem == "系统管理员")
i = 1;然后把i写到数据库对应的字段就可以了
解决方案 »
- 循环执行多条SQL时,如何在报错后继续执行SQL
- 新人求助!有关CheckBox的数据绑定
- c#获取系统信息。顶者有分
- C# HttpWebRequest 得到的页面,用什么编码方式解析都是乱码? 请高手指教!
- ibatis中创建临时表,解决立即给分
- 可付费 请问用wince 下 .net 怎么开发媒体播放器!!!!!!!!!!!!!!!!!
- 关于SqlServer内Image字段的读取和存贮问题?高分求助
- ************ 例外詳細資訊: System.Data.SqlClient.SqlException: 程序 'look6' 預期使用未提供的參數 '@radio'
- 转义符@该如何除去?
- 在做一个单机版的管理系统 求一个实现会员图片功能的方法 在线等 马上给分 急! winform c#
- 怎么样在C#中调用一个外部程序??
- 如何让PrintPreviewControl控件在Document.DefaultSetting更改生效后立即显示新设置的预览页面?
class Myclass
{
private string name;
private int id;
public string Name
{
get {return name;
}
public int Id
{
get{return id;} public Mycalss(string name,int id)
{
this.name = name;
this.id = id;
} public override string ToString()
{
return this.name;
}
} 然后声明许多这样的实例Mycalss c = new Mycalss("系统管理员",1);
..........................然后加进去combbox
this.combbox.item.add(c);
.....
然后取出来Mycalss cc = (Mycalss)this.cobbox.selectitem;
cc.Id就是你要的东西。
int i;
i=CombBox1.SelectIndex;
switch (i)
{
case 0:
//...
break;
case 1:
//...
break;
//...
default:break;
}
然后combbox的item其实是一个object类型的,你可以加任何东西到里面,而combbox显示给你的就是这个object.ToString()。所以上面的类中要过载ToString()方法。取出combbox的选中的item,因为是一个object类型的,所以要做一个类型转换,转换成自定义类型的,然后取出他的属性Id就可以了。
SqlConnection conn = new SqlConnection("server=pany;database=exoaextend;uid=sa;pwd=123");
SqlDataAdapter cmd = new SqlDataAdapter("select * from exoaunits", conn);
DataSet ds = new DataSet();
cmd.Fill(ds, "units");
//combobox绑定数据源
comboBox1.DataSource = ds.Tables["units"].DefaultView;
comboBox1.ValueMember = "UnitID"; //指定ID字段
comboBox1.DisplayMember = "UnitName";//指定显示字段
conn.Close();
//取得ID值
MessageBox.Show(comboBox1.SelectedValue.ToString());