using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class DBOperation
{
private static string conn = "Data Source=.;Initial Catalog=qq;Integrated Security=True";
//User ID=sa;Password=123456";如果Password为空,可以不写
public static SqlConnection con = new SqlConnection(conn);
string strMsg="";
#region 异常处理
public void Conn()
{
try
{
//打开数据库
con.Open();
CheckUserInFo();
Console.WriteLine("打开成功");
Console.WriteLine(strMsg);
}
catch (Exception ex)
{
Console.WriteLine("异常:{0}", ex.Message);
}
finally
{
//关闭数据
con.Close();
Console.WriteLine("关闭成功");
Console.ReadLine();
}
}
#endregion
#region
public string CheckUserInFo()
{
Console.Write("请输入QQ号:");
int ID = int.Parse(Console.ReadLine());
Console.Write("请输入密码:");
string pwd = Console.ReadLine();
string sql =string.Format("select QQid,password from qquser where qqid={0} and password={1}",ID,pwd);
SqlCommand com = new SqlCommand(sql,con);
int i = (int)com.ExecuteScalar();
if (i != 1)
{
strMsg = "输入错误";
return strMsg;
}
else
{
strMsg = "登陆成功";
return strMsg;
}
}
#endregion
}
}
倚天杖
Helenr
慕妹3242003
holdtom
LEATH