无法将类型为“System.Int64”的对象强制转换为类型“System.String”。
stringconnString=System.Web.Configuration.WebConfigurationManager.ConnectionStrings["...
string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["AdminConn2.0"].ToString(); //数据连接,参考“陌香”-http://www.cnblogs.com/_zjl/archive/2011/05/29/2062211.html,AdminConn2.0为web.config里面配置的数据连接字符串的名字。
SqlConnection MyConnection = new SqlConnection(connString);
SqlCommand MyCommand = new SqlCommand("SELECT L_id,L_name,L_email,L_content,L_datetime,L_recontent,L_recontenttime,L_recontentor FROM LeaveMessageDate", MyConnection); //定义一个数据库操作指令
SqlDataReader datadr = null;
try
{
MyConnection.Open();
datadr = MyCommand.ExecuteReader();
if (datadr.Read())
{
this.labId.Text = datadr.GetString(0);
this.txtName.Text = datadr.GetString(1);
this.labTime.Text = datadr.GetString(2);
this.labEmail.Text = datadr.GetString(3);
this.txtContent.Text = datadr.GetString(4);
this.labReContentor.Text = datadr.GetString(5);
this.labReTime.Text = datadr.GetString(6);
this.labReContent.Text = datadr.GetString(7);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
MyConnection.Close();
}
请老师修正,我是小白,这种写法对不,若不对,请给个例子,谢谢。
Dispose();
} 展开
SqlConnection MyConnection = new SqlConnection(connString);
SqlCommand MyCommand = new SqlCommand("SELECT L_id,L_name,L_email,L_content,L_datetime,L_recontent,L_recontenttime,L_recontentor FROM LeaveMessageDate", MyConnection); //定义一个数据库操作指令
SqlDataReader datadr = null;
try
{
MyConnection.Open();
datadr = MyCommand.ExecuteReader();
if (datadr.Read())
{
this.labId.Text = datadr.GetString(0);
this.txtName.Text = datadr.GetString(1);
this.labTime.Text = datadr.GetString(2);
this.labEmail.Text = datadr.GetString(3);
this.txtContent.Text = datadr.GetString(4);
this.labReContentor.Text = datadr.GetString(5);
this.labReTime.Text = datadr.GetString(6);
this.labReContent.Text = datadr.GetString(7);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
MyConnection.Close();
}
请老师修正,我是小白,这种写法对不,若不对,请给个例子,谢谢。
Dispose();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询