【问题标题】:A get or set accessor expected需要一个 get 或 set 访问器
【发布时间】:2017-10-15 09:16:31
【问题描述】:

我正在获取或设置访问器除外

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\KARTHICK\Documents\test.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "insert into table1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
            cmd.ExecuteNonQuery();
            con.Close();

            MessageBox.Show("record inserted successfully");
        }
        public void display
        {
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from table1";
            cmd.ExecuteNonQuery();
            DataTable dt=new DataTable();
            SqlDataAdapter dt= new SqlDataAdapter(cmd);
            da.fill(dt);
            con.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
      display();
        }
    }
}

【问题讨论】:

  • 你在public void display上的函数名后面缺少()
  • 你能在你的代码中添加一些描述吗?
  • 在哪一行得到错误?顺便说一句,听说过sql injection attacks

标签: c# winforms


【解决方案1】:

你有一些错误:

  1. ()添加到public void display的末尾

  2. SqlDataAdapter dt= new SqlDataAdapter(cmd); 处存在名为dt 的重复变量

  3. da 变量未在 da.fill(dt); 中定义

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-09
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 2021-05-19
    • 1970-01-01
    相关资源
    最近更新 更多