Time |
DateTime |
1.查询并获取DateTime类型数据
stringConnectionStrings="Data Source =LAPTOP-L2T1PCV3\\MYSQLSERVER;"+"Initial Catalog = TimeDateTime; Integrated Security = True; "+"User Id = user; Password=123456"; //这里是作者为了美观才换行,可以不用换行 //Data Source 数据库服务器的名称//Initial Catalog Time所在的数据库的名称usingSqlConnectionconn=new(ConnectionStrings); stringsql="selert Time from [Time]";//Time 为表的名字 conn.Open(); SqlCommandcmd=new(sql, conn); SqlDataReaderreader=cmd.ExecuteReader(); conn.Close(); DateTimeTime; while(reader.(Read()) { Time=reader.GetDateTime(0); }
2.插入
//基本语句与查询相同,这里作者就稍微改了一点点DateTimetime=DateTime.Now.ToString(); sql=string.Format("insert into [Time] value('{0}')",time);
3.更新
DateTimetime=DateTime.Now.ToString(); sql=string.Format("update [Time] set Time='{0}'",time);