The namespace KDSystem
{
The class DBHelper
{
Public static SqlConnection GetConnection ()
{
//the connection string
String constr=@ "Data Source=(LocalDB) \ MSSQLLocalDB; AttachDbFilename=C: \ Users \ Desktop \ Windows \ \ DE KDSystem \ KDSystem \ KDSystem \ KDS MDF. Integrated Security=True";
SqlConnection con=new SqlConnection (constr);
Return con;
}
}
}
CodePudding user response:
//insert the data code, the running error: later the SQL user changed to [user], can insert, but stilSqlConnection con=DBHelper. GetConnection ();
Con. The Open ();
If (con) State==ConnectionState) Open)
{
String SQL="insert into [user] values ('" + textBox1. Text + "', '" + textBox2. Text +") ";
//SQL=string. The string Format (" insert into user values (' {0} ', '{1}') ", the textBox1. Text, textBox2. The Text).
SqlCommand CMD=new SqlCommand (SQL, con);
If (CMD) ExecuteNonQuery () & gt; 0)
{
MessageBox. Show (" registered success!" );
}
The else
MessageBox. Show (" registration failed!" );
}