create test
(
fd_seq integer not null,
fd_name varchar2(10) not null,
fd_sex integer not null);要求字段fd_sex显示 1男 0女
已经确保内数据无错误,可总是显示 system.formatexception:datagridviewcomboboxcell值无效,
开发环境vs2008
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;using System.Data.OracleClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
getdata();
} private DataTable dt; private void setcol()
{
dt = new DataTable();
dt.Columns.Add("Key", typeof(string));
dt.Columns.Add("Value", typeof(int)); DataRow dr;
dr = dt.NewRow();
dr["Key"] = "男";
dr["Value"]=0;
dt.Rows.Add(dr); dr = dt.NewRow();
dr["Key"] = "女";
dr["Value"] = 1;
dt.Rows.Add(dr); dt.AcceptChanges();
fd_sex.DataSource = dt;
fd_sex.DisplayMember = "Key";
fd_sex.ValueMember = "Value"; } private void getdata()
{
try
{ setcol(); string sql;
sql = "Select * from test";
DataTable dt1 = OraHelper.ReturnDataSet(CommandType.Text, sql, null).Tables[0]; this.dataGridView1.DataSource = dt1;
}
catch (Exception exp)
{ MessageBox.Show(exp.Message);
}
}
}
}
(
fd_seq integer not null,
fd_name varchar2(10) not null,
fd_sex integer not null);要求字段fd_sex显示 1男 0女
已经确保内数据无错误,可总是显示 system.formatexception:datagridviewcomboboxcell值无效,
开发环境vs2008
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;using System.Data.OracleClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
getdata();
} private DataTable dt; private void setcol()
{
dt = new DataTable();
dt.Columns.Add("Key", typeof(string));
dt.Columns.Add("Value", typeof(int)); DataRow dr;
dr = dt.NewRow();
dr["Key"] = "男";
dr["Value"]=0;
dt.Rows.Add(dr); dr = dt.NewRow();
dr["Key"] = "女";
dr["Value"] = 1;
dt.Rows.Add(dr); dt.AcceptChanges();
fd_sex.DataSource = dt;
fd_sex.DisplayMember = "Key";
fd_sex.ValueMember = "Value"; } private void getdata()
{
try
{ setcol(); string sql;
sql = "Select * from test";
DataTable dt1 = OraHelper.ReturnDataSet(CommandType.Text, sql, null).Tables[0]; this.dataGridView1.DataSource = dt1;
}
catch (Exception exp)
{ MessageBox.Show(exp.Message);
}
}
}
}
setcol(); <-- 这个在 getdata() 这个方法即使调用了做了什么?
fd_sex <-- 这个是什么控件?this.dataGridView1.DataSource = dt1; <-- dt1,你绑上去的是... ...
绑到datagridview1上的 是select * from test
看看你的dt1里面对应的fd_sex值是否都是0或1
fd_sex是否绑定给了Combox列