C#连接数据库字符串:
混合身份登录:Data Source=王蕾\WANGLEI\SQLSERVER2008;Initial Catalog=MyTest;Persist Security Info=True;User ID=sa;Password=yhb@163
windows登录:data source=王蕾\WANGLEI\SQLSERVER2008;database=csdnnews;integrated security=true
连接SQLExpress:Data Source=王蕾\WANGLEI\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True
C#实现用户登录的代码:
string str = "server=.;database=数据库名;integrated security=true";
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = str;
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = sqlcon;
sqlcmd.CommandText = "select *from 表名 where Name='"+this.TextBox1.Text+"' and Shouji='"+this.TextBox2.Text+"'";
sqlcon.Open();
SqlDataReader reader = sqlcmd.ExecuteReader();
if (reader.Read())
{
this.Response.Write("登陆成功");
}
else
{
this.Response.Write("登陆失败");
}
reader.Close();
sqlcon.Close();
C#中时间对比的应用:
DateTime DateTime1, DateTime2 = DateTime.Now ;//现在时间
DateTime1 =Convert.ToDateTime("2009-04-24 20:00:00"); //设置要求的减的时间
string dateDiff = null;
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration(); //显示时间
dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" ;
C#对数据库的调用和时间的比对
最新推荐文章于 2024-06-23 14:43:59 发布