C# 需要获取或设置访问器
我正在获取或设置访问器(例外)C# 需要获取或设置访问器,c#,winforms,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;C
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();
}
}
}
你有一些错误:
()
添加到公共无效显示的末尾
dt
atSqlDataAdapter dt=newsqldataadapter(cmd)的重复变量代码>
da
变量未在da.fill(dt)处定义代码>
您在
公共无效显示上的函数名之后缺少()
。您可以为代码添加一些描述吗?在哪一行获取错误?顺便说一句,听说过吗?