ADO.NET的问题
public void Studentinfo()
{
Multiplexing m = new Multiplexing();
SqlDataReader d = null;
Console.WriteLine("请输入学生姓名:");
string name = Console.ReadLine();
string Sql = string.Format("select * from Student where StudentName = '{0}'", name);
bool has = m.Has(Sql);
if (has == true)
{
string sql = string.Format("select StudentNo,LoginPwd,StudentName,Gender,GradeId,Phone,Address,BornDate,Email,IdentityCard from Student where StudentNo = '{0}'", name);
d = m.Reader(sql);
Console.WriteLine("学号\t密码\t姓名\t性别\t年纪\t电话\t地址\t出生日期\t邮箱\t身份证");
while (d.Read())
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}", d["StudentNo"], d["LoginPwd"], d["StudentName"], d["Gender"], d["GradeId"], d["Phone"], d["Address"], d["BornDate"], d["Email"], d["IdentityCard"]);
}
}
else
{
Console.WriteLine("您输入的姓名不存在,请核对!");
}
}
这段代码运行时显示无法将Varchar转换为int值,我没做转换啊
------解决方案--------------------
string sql = string.Format("select StudentNo,LoginPwd,StudentName,Gender,GradeId,Phone,Address,BornDate,Email,IdentityCard from Student where StudentNo = '{0}'", name);
StudentNo 貌似是个int型吧