C#中connectionString上下文中不存在名称是什么意思 20
privatevoidbutton1_Click(objectsender,EventArgse){SqlConnectioncon=newSqlConnection(c...
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
connectionString="Data Source=localhost;Initial Catalog=数据库名称;User ID=用户名;Password=密码"
try
{
string sql = "select * from YNJDGLXT.dbo where TYNJDGLXT.local用户名=@userName and YNJDGLXT.密码=@UserPassword";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@userName",txtUserName.Text);
cmd.Parameters.AddWithValue("@Password",txtUserPassword.Text);
con.Open();
//cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("成功!");
}
else
{
MessageBox.Show("失败!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
}
} 展开
{
SqlConnection con = new SqlConnection(connectionString);
connectionString="Data Source=localhost;Initial Catalog=数据库名称;User ID=用户名;Password=密码"
try
{
string sql = "select * from YNJDGLXT.dbo where TYNJDGLXT.local用户名=@userName and YNJDGLXT.密码=@UserPassword";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@userName",txtUserName.Text);
cmd.Parameters.AddWithValue("@Password",txtUserPassword.Text);
con.Open();
//cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("成功!");
}
else
{
MessageBox.Show("失败!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询