请各位看看出了什么问题,就是运行不了
private void button1_Click(object sender, System.EventArgs e)
{
string selectCmd = "SELECT * FROM SCORE WHERE name = '" +
cxbox.Text + "'";
string connStr =
"Provider=Microsoft.OLEDB.DB;Data Source=SCOREDB.mdb";
SqlConnection conn;
SqlCommand cmd;
SqlDataReader myReader;
conn = new SqlConnection();
conn.Open();
cmd = new SqlCommand();
cmd.Connection=conn;
myReader = cmd.ExecuteReader();
if (myReader.Read())
{
xsbox.Text = "学号\t" + myReader["id_no"] + "\n";
xsbox.Text += "姓名\t" + myReader["name"] + "\n";
xsbox.Text += "语文\t" + myReader["chi"] + "\n";
xsbox.Text += "英语\t" + myReader["eng"] + "\n";
xsbox.Text += "数学\t" + myReader["math"];
}
else
{
xsbox.Text = "找不到这个学生的成绩!";
}
myReader.Close();
conn.Close();
private void button1_Click(object sender, System.EventArgs e)
{
string selectCmd = "SELECT * FROM SCORE WHERE name = '" +
cxbox.Text + "'";
string connStr =
"Provider=Microsoft.OLEDB.DB;Data Source=SCOREDB.mdb";
SqlConnection conn;
SqlCommand cmd;
SqlDataReader myReader;
conn = new SqlConnection();
conn.Open();
cmd = new SqlCommand();
cmd.Connection=conn;
myReader = cmd.ExecuteReader();
if (myReader.Read())
{
xsbox.Text = "学号\t" + myReader["id_no"] + "\n";
xsbox.Text += "姓名\t" + myReader["name"] + "\n";
xsbox.Text += "语文\t" + myReader["chi"] + "\n";
xsbox.Text += "英语\t" + myReader["eng"] + "\n";
xsbox.Text += "数学\t" + myReader["math"];
}
else
{
xsbox.Text = "找不到这个学生的成绩!";
}
myReader.Close();
conn.Close();
你你都没有用到sql语句。。selectCmd
conn.Open();
这样加吗?不过加了也会出错,急阿!!!!
cmd = new SqlCommand();
都没有初始化
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 你mdb文件路径 + ";";
System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(strConn);
cn.Open();
System.Data.OleDb.OleDbDataAdapter sqlda = new System.Data.OleDb.OleDbDataAdapter("你的SQL语句",strConn);
DataSet ds1 = new DataSet();
//添充数据集
sqlda.Fill(ds1);
cn.Close();
//然后从数据集取出你想要的数据
{
xsbox.Text = "学号\t" + ds1.Tables[0].Rows[i]["id_no"].ToString() + "\n";
xsbox.Text += "姓名\t" + ds1.Tables[0].Rows[i]["name"].ToString() + "\n";
xsbox.Text += "语文\t" + ds1.Tables[0].Rows[i]["chi"].ToString() + "\n";
xsbox.Text += "英语\t" + ds1.Tables[0].Rows[i]["eng"].ToString() + "\n";
xsbox.Text += "数学\t" + ds1.Tables[0].Rows[i]["math"].ToString();
}
cxbox.Text + "'";
string connStr =
"Provider=Microsoft.OLEDB.DB;Data Source=SCOREDB.mdb";
上面这两个东东根本就没有用上肯定错啦。。
导致conn = new SqlConnection();
cmd = new SqlCommand();
都没有初始化