public string ListUIDByEID(int EID)
{
SqlConnection cnn = new SqlConnection();
SqlCommand cmm = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
string UID = "";
cnn.ConnectionString = "server=.;database=ZQVote;integrated security=true";
cmm.Connection = cnn;
cmm.CommandText = "select UID from elector where EID='" + EID + "'";
cnn.Open();
da.SelectCommand = cmm;
da.Fill(ds);
for (int i = 0; i < cmm.ExecuteNonQuery(); i++)
{
UID += ds.Tables[0].Rows[i][0].ToString() + ",";
} UID = UID.TrimEnd(',');
return UID;
}
这段代码的作用是根据elector表中的分类情况EID(elector表中字段),取得用户ID:UID(elector表中字段)
得出来的UID要用到sql语句:"UID in (" +UID+ ")"
根据我的程序报错,问题应该出在这个函数里面
求各位大侠赐教!!
{
SqlConnection cnn = new SqlConnection();
SqlCommand cmm = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
string UID = "";
cnn.ConnectionString = "server=.;database=ZQVote;integrated security=true";
cmm.Connection = cnn;
cmm.CommandText = "select UID from elector where EID='" + EID + "'";
cnn.Open();
da.SelectCommand = cmm;
da.Fill(ds);
for (int i = 0; i < cmm.ExecuteNonQuery(); i++)
{
UID += ds.Tables[0].Rows[i][0].ToString() + ",";
} UID = UID.TrimEnd(',');
return UID;
}
这段代码的作用是根据elector表中的分类情况EID(elector表中字段),取得用户ID:UID(elector表中字段)
得出来的UID要用到sql语句:"UID in (" +UID+ ")"
根据我的程序报错,问题应该出在这个函数里面
求各位大侠赐教!!
{
UID += ds.Tables[0].Rows[i][0].ToString() + ",";
}我感觉问题在这一段里!你调试下看看!Tables[0].Rows[i][0]你这里的表格我个人有点看发!建议你在看看!
User ID=sa;Password=123;Data Source=.;Initial Catalog=ZQVote
for (int i = 0; i < cmm.ExecuteNonQuery(); i++)
{
UID += ds.Tables[0].Rows[i][0].ToString() + ",";
}
cmm.ExecuteNonQuery()这个是什 么意思
是不是这个地方问题,这个修改for (int i = 0; i < ds.Tables[0].Rows.Count;i++)
{
UID += ds.Tables[0].Rows[i][0].ToString() + ",";
}
还有那个报错是:string a=ListUIDByEID(EID),EID是dropdownlist的索引值
再把a用到sql语句中:"UID in (" +a+ ")"
然后报错是:列名“a”无效
列名“a”无效
列名“a”无效
我刚学的c#,问题有点弱智吧,希望各位不吝赐教