c# 将字段写入数组,并添加到access数据库时提示:“未将对象引用设置到对象的实例。第102行出错
protectedvoidbtn_incCount_Click(objectsender,EventArgse){superConncn_icm=newsuperConn...
protected void btn_incCount_Click(object sender, EventArgs e) { superConn cn_icm = new superConn("salaryMangement.mdb"); cn_icm.open(); string str_count = "SELECT count(inc_itemsName) as itmCount FROM t_incomeItems INNER JOIN t_period ON t_incomeItems.inc_ID = t_period.pr_incItemsID where pr_data_short = '" + dl_incBelong.SelectedItem.Value + "'"; OleDbDataReader dr_count = cn_icm.getdatareader(str_count); if(dr_count.Read()) { itmCt =(int) dr_count["itmCount"]; } string str_icm = "SELECT * FROM t_incomeItems INNER JOIN t_period ON t_incomeItems.inc_ID = t_period.pr_incItemsID where pr_data_short='"+dl_incBelong.SelectedItem.Value + "' order by pr_order"; OleDbDataReader dr_icm = cn_icm.getdatareader(str_icm); Column[] columns = new Column[itmCt]; i = 0; while (dr_icm.Read()) { if (dr_icm.Read()) { i++; columns[i - 1].Name = dr_icm["inc_itemsName"].ToString(); columns[i - 1].Type = DataTypeEnum.adWChar; columns[i - 1].DefinedSize = 50; } } cn_icm.close(); superCreateTable sct = new superCreateTable(); sct.CreateAccessTable("salaryMangement.mdb", "t_icmCollections", columns); }
展开
2个回答
展开全部
object o=null;
using (OleDbConnection con = new OleDbConnection(connectionStr))
{
string query = string.Format("select top 1 STUname from form1 where username = '{0}',username);
using(OleDbCommand cmd = new OleDbCommand(query,con)
{
con.Open();
object o = cmd.ExecuteScalar();//根据你的STUname
数据类型,再将 o 转换成相应的类型,比如 是字符串 就可以 string s = o.ToString();
}
using (OleDbConnection con = new OleDbConnection(connectionStr))
{
string query = string.Format("select top 1 STUname from form1 where username = '{0}',username);
using(OleDbCommand cmd = new OleDbCommand(query,con)
{
con.Open();
object o = cmd.ExecuteScalar();//根据你的STUname
数据类型,再将 o 转换成相应的类型,比如 是字符串 就可以 string s = o.ToString();
}
追问
???
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询