刚学C#不久 遇到个连接数据库的问题 大家进来看看哪错了
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 数据库登陆注册
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection mysql = new SqlConnection();
mysql.ConnectionString = "server=USER-066E82BD8E\\SPF;Trusted_Connection=yes;database=pubs";
mysql.Open();
string selectStr = "select * from userwhere username = " +"'" + this.textBox1.Text + "and password=" + "'" + this.textBox2.Text + "'";
SqlCommand cmd = new SqlCommand(selectStr, mysql);
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
MessageBox.Show(this,"登陆成功!");
else
MessageBox.Show(this,"登陆失败!");
mysql.Close();
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection("server =USER-066E82BD8E\\SPF;Trusted_Connection=yes;database=pubs");
myconn.Open();
MessageBox.Show(this, "OK");
myconn.Close();
}
}
}
where and那边有错 ...不知道怎么改