public string GetSystemDate()
{
try
{ if(this.sqlConnection1.State == ConnectionState.Closed)
{
this.sqlConnection1.Open();
}
}
catch
{
MessageBox.Show("数据库连接失败!");
return("");
}
SqlCommand cmm = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
cmm.Connection = sqlConnection1;
sda.SelectCommand = cmm;
string sDay;
System.Data.SqlClient.SqlDataReader read;
try
{
sda.SelectCommand.CommandText="select getdate() from systypes";
read=sda.SelectCommand.ExecuteReader();
read.Read();
sDay=read.GetDateTime(0).ToString();
read.Close();
return(sDay);
}
catch(System.Exception en)
{
MessageBox.Show(""+en.Message);
return("");
}
finally
{
cmm.Dispose();
sda.Dispose();
sqlConnection1.Close();
}
}
{
try
{ if(this.sqlConnection1.State == ConnectionState.Closed)
{
this.sqlConnection1.Open();
}
}
catch
{
MessageBox.Show("数据库连接失败!");
return("");
}
SqlCommand cmm = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
cmm.Connection = sqlConnection1;
sda.SelectCommand = cmm;
string sDay;
System.Data.SqlClient.SqlDataReader read;
try
{
sda.SelectCommand.CommandText="select getdate() from systypes";
read=sda.SelectCommand.ExecuteReader();
read.Read();
sDay=read.GetDateTime(0).ToString();
read.Close();
return(sDay);
}
catch(System.Exception en)
{
MessageBox.Show(""+en.Message);
return("");
}
finally
{
cmm.Dispose();
sda.Dispose();
sqlConnection1.Close();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货