C# 报错 非静态的字段、方法或属性 要求对象引用
书上给的一段代码 运行后总是报错
错误 1 非静态的字段、方法或属性“WindowsFormsApplication1.LibrarymanageDataSet100.Readerinfo.get”要求对象引用
求大神指导 新手学习中
完整代码如下 红色是出错的地方
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form4 : Form3
{
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“librarymanageDataSet100.Readerinfo”中。您可以根据需要移动或删除它。
this.readerinfoTableAdapter.Fill(this.librarymanageDataSet100.Readerinfo);
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=DESKTOP-I1M8DPO;Initial Catalog=Librarymanage;uid=sa;pwd=123";
con.Open();
SqlCommand sqlcom = con.CreateCommand();
sqlcom.CommandText = "select * from Readerinfo";
SqlDataReader dr = sqlcom.ExecuteReader();
while (dr.Read())
{ comboBox2.Items.Add(dr["Reader_ID"]); }
comboBox1.SelectedIndex = 0;
dr.Close();
con.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int index1;
index1 = comboBox1.SelectedIndex;
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=DESKTOP-I1M8DPO;Initial Catalog=Librarymanage;uid=sa;pwd=123";
con.Open();
if (MessageBox.Show("是否要删除选中的用户?", "删除确认",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
string strSql = "delete from Readerinfo where Reader_ID=" + "'" +
textBox1.Text.Trim() + "'";
SqlCommand cmd = new SqlCommand(strSql, con);
cmd.ExecuteNonQuery();
comboBox1.Items.Clear();
SqlCommand sqlcom = con.CreateCommand();
sqlcom.CommandText = "Select * from Readerinfo";
SqlDataReader dr = sqlcom.ExecuteReader();
while (dr.Read())
{ comboBox1.Items.Add(dr["Reader_ID"]); }
MessageBox.Show("删除成功!");
dr.Close();
con.Close();
readerinfoTableAdapter.Fill(LibrarymanageDataSet100.Readerinfo);
comboBox1.SelectedIndex = 0;
}
}
private void button3_Click(object sender, EventArgs e)
{
string strCon = "Data Source=DESKTOP-I1M8DPO;Initial Catalog=Librarymanage;uid=sa;pwd=123";
SqlConnection sqlcon = new SqlConnection(strCon);
SqlDataAdapter sqlda = new SqlDataAdapter("select * from Readerinfo", sqlcon);
DataSet myds = new DataSet();
sqlda.Fill(myds, "tabName");
dataGridView1.DataSource = myds.Tables["tabName"];
}
private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
{
bindingSource1.Filter = "Reader_ID='" + comboBox1.Text.Trim() + "'";
}
}
}