ExecuteReader: CommandText 属性尚未初始化
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Student
{
public partial class RPT : Form
{
public RPT()
{
InitializeComponent();
}
private string Rptstrconn;
private SqlConnection sqlrptconn;
private SqlDataAdapter sqlrptda;
private string Rptconnstr="Data Source=WWW-F9EEA54BDCA;Initial Catalog=STUDENT;User ID=sa;Pwd=jxlsqd;Integrated Security=False";
private SqlCommandBuilder sqlrptcomm;
private DataSet Rptset = new DataSet();
private void button1_Click(object sender, EventArgs e)
{
Rptstrconn = "select * from REWARD_PUNUSHMENT where STUDENT = " + "'" + txtrpt.Text.ToString().Trim() + "'";
sqlrptconn = new SqlConnection(this.Rptconnstr);
sqlrptda = new SqlDataAdapter(this.Rptstrconn, this.sqlrptconn);
Rptset.Clear();
sqlrptda.Fill(Rptset, "REWARD_PUNUSHMENT");
datrpt.DataSource = Rptset.Tables[0];
}
private void button5_Click(object sender, EventArgs e)
{
int row = this.datrpt.VisibleRowCount;
this.datrpt.CurrentCell = new DataGridCell(row + 1, 0);
}
private void RPT_Load(object sender, EventArgs e)
{
Rptstrconn = "select ID as 记录号,STUDENT as 学号,LEVEL as 奖惩代号,TIME as 奖惩时间,DESCRIPTION as 描述 from REWARD_PUNUSHMENT";
sqlrptconn = new SqlConnection(this.Rptconnstr);
sqlrptda = new SqlDataAdapter(this.Rptstrconn, this.sqlrptconn);
Rptset.Clear();
sqlrptda.Fill(Rptset, "REWARD_PUNUSHMENT");
datrpt.DataSource = Rptset.Tables[0];
}
private void button4_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确定要退出系统吗?", "确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
int row = this.datrpt.VisibleRowCount;
this.datrpt.CurrentCell = new DataGridCell(row + 1, 0);
if (Rptset.HasChanges())
{
sqlrptconn = new SqlConnection(this.Rptconnstr);
sqlrptda = new SqlDataAdapter(this.Rptstrconn, this.sqlrptconn);
sqlrptcomm = new SqlCommandBuilder(sqlrptda);
sqlrptda.Update(Rptset.GetChanges(), "REWARD_PUNUSHMENT");
Rptset.AcceptChanges();
MessageBox.Show("信息修改成功!");
}
}
private void button3_Click(object sender, EventArgs e)
{
int rowNumber = this.datrpt.CurrentCell.RowNumber;
//try
//{
this.Rptset.Tables[0].Rows[rowNumber].Delete();
// DataSet Rptset = new DataSet();
this.sqlrptconn = new SqlConnection(this.Rptconnstr);
sqlrpt