期望获取或设置访问者

时间:2017-10-15 09:16:31

标签: c# winforms

我得到或设置访问者除外

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();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

你有一些错误:

  1. ()添加到public void display

  2. 的末尾
  3. dt

  4. 处复制名为SqlDataAdapter dt= new SqlDataAdapter(cmd);的变量
  5. da变量未在da.fill(dt);
  6. 中定义