private static void OpenSqlConnection() { string connectionString = GetConnectionString(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); Console.WriteLine("ServerVersion: {0}", connection.ServerVersion); Console.WriteLine("State: {0}", connection.State); } }static private string GetConnectionString() { // To avoid storing the connection string in your code, // you can retrieve it from a configuration file, using the // System.Configuration.ConfigurationSettings.AppSettings property return "Data Source=(local);Initial Catalog=AdventureWorks;" + "Integrated Security=SSPI;"; }
SqlConnection conn = new SqlConnection("server=zwl;database=login;uid=sa;pwd=admin;") conn.open(); SqlCommand = new SqlCommand("select count(*) from login where userName =""+userName+"" and userPwd=""+userPwd+"",conn); int count=Convert.ToInt32(cmd.ExecuteScalar()); //ExecuteScalar()执行查询并返回所查询结果集的第一行第一列 if(count>0){ Response.Redirect("main.aspx"); } else { Response.Redirect("error.aspx"); }
SqlConnection conn = new SqlConnection("server=.;database=pubs;uid=sa;pwd=;"); conn.open();
SqlConnection conn = new SqlConnection("server=zwl;database=login;uid=sa;pwd=admin;") conn.open(); SqlCommand = new SqlCommand("select count(*) from login where userName =""+userName+"" and userPwd=""+userPwd+"",conn); int count=Convert.ToInt32(cmd.ExecuteScalar()); //ExecuteScalar()执行查询并返回所查询结果集的第一行第一列 if(count>0){ Response.Redirect("main.aspx"); } else { Response.Redirect("error.aspx"); }
{
string connectionString = GetConnectionString();
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
Console.WriteLine("State: {0}", connection.State);
}
}static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file, using the
// System.Configuration.ConfigurationSettings.AppSettings property
return "Data Source=(local);Initial Catalog=AdventureWorks;"
+ "Integrated Security=SSPI;";
}
conn.open();
SqlCommand = new SqlCommand("select count(*) from login where userName =""+userName+"" and userPwd=""+userPwd+"",conn);
int count=Convert.ToInt32(cmd.ExecuteScalar());
//ExecuteScalar()执行查询并返回所查询结果集的第一行第一列
if(count>0){
Response.Redirect("main.aspx");
} else {
Response.Redirect("error.aspx");
}
conn.open();
难怪好多程序员的薪水不如民工,看到楼主这帖我算是明白了...------------------------------------------------------------------------
........
conn.open();
SqlCommand = new SqlCommand("select count(*) from login where userName =""+userName+"" and userPwd=""+userPwd+"",conn);
int count=Convert.ToInt32(cmd.ExecuteScalar());
//ExecuteScalar()执行查询并返回所查询结果集的第一行第一列
if(count>0){
Response.Redirect("main.aspx");
} else {
Response.Redirect("error.aspx");
}