我对SQL有一点问题,它说“public Form1();在代码的最顶端,根据我正在关注的begginers指南,应该有一个带有3个点的小盒子(像这[...])而不是“;”
public Form1();
System.Data.SqlClient.SqlConnection con;
private void Form1_Load(object sender, EventArgs e)
{
con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString="Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Wee Jimmy\\Documents\\MyWorkers.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
con.Open();
MessageBox.Show("Open");
con.Close();
MessageBox.Show("Closed");
请有人帮忙我准备好了。错误说,错误1'SQL_Connection.Form1.Form1()'必须声明一个正文,因为它没有标记为abstract,extern或partial C:\用户\ Wee Jimmy \ Documents \ Visual Studio 2010 \ Projects \ SQL Connection \ SQL Connection \ Form1.cs 15 16 SQL连接
答案 0 :(得分:1)
更改第一行:
public Form1();
为:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
答案 1 :(得分:0)
试试这个 -
public Form1()
{
System.Data.SqlClient.SqlConnection con;
private void Form1_Load(object sender, EventArgs e)
{
con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString="Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Wee Jimmy\\Documents\\MyWorkers.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
con.Open();
MessageBox.Show("Open");
con.Close();
MessageBox.Show("Closed");
}
}