我有一个按钮,<asp:button id="after" text="下一条" runat=server> 作用是取数据库中的数据,一条一条显示在界面上。
k是我定义的全局变量,public static int k=0; DataRow row=ds.Tables[0].Rows[k];
sick_id.Text=row["sick_id"].ToString();
sick_name.Text=Convert.ToString(row["sick_name"]);
dropdownlist2.Items[0].Text=Convert.ToString(row["come_status"]);
dropdownlist1.Items[0].Text=Convert.ToString(row["sex"]);
dropdownlist3.Items[0].Text=Convert.ToString(row["birth_date"]).Substring(0,4);
dropdownlist4.Items[0].Text=Convert.ToDateTime(row["birth_date"]).ToString("yyy-MM-dd").Substring(5 ,2);
Dropdownlist16.Items[0].Text=Convert.ToDateTime(row["birth_date"]).ToString("yyy-MM-dd").Substring(8,2);
k=k+1;在本地是没有错误的,一条一条可以显示出来,但是我上传到空间上面,就出现了以下的错误,错误如下:
我用的是.net 2003开发的,是不是和空间的.net framework version有关系啊。
Server Error in '/' Application.
--------------------------------------------------------------------------------Object cannot be cast from DBNull to other types.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToDateTime(IFormatProvider provider) +54
System.Convert.ToDateTime(Object value) +29
_800service.index2.look_up(String sql, Int32 k) in e:\asp.net\800service\index2.aspx.cs:1101
_800service.index2.after_Click(Object sender, EventArgs e) in e:\asp.net\800service\index2.aspx.cs:1375
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832
k是我定义的全局变量,public static int k=0; DataRow row=ds.Tables[0].Rows[k];
sick_id.Text=row["sick_id"].ToString();
sick_name.Text=Convert.ToString(row["sick_name"]);
dropdownlist2.Items[0].Text=Convert.ToString(row["come_status"]);
dropdownlist1.Items[0].Text=Convert.ToString(row["sex"]);
dropdownlist3.Items[0].Text=Convert.ToString(row["birth_date"]).Substring(0,4);
dropdownlist4.Items[0].Text=Convert.ToDateTime(row["birth_date"]).ToString("yyy-MM-dd").Substring(5 ,2);
Dropdownlist16.Items[0].Text=Convert.ToDateTime(row["birth_date"]).ToString("yyy-MM-dd").Substring(8,2);
k=k+1;在本地是没有错误的,一条一条可以显示出来,但是我上传到空间上面,就出现了以下的错误,错误如下:
我用的是.net 2003开发的,是不是和空间的.net framework version有关系啊。
Server Error in '/' Application.
--------------------------------------------------------------------------------Object cannot be cast from DBNull to other types.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToDateTime(IFormatProvider provider) +54
System.Convert.ToDateTime(Object value) +29
_800service.index2.look_up(String sql, Int32 k) in e:\asp.net\800service\index2.aspx.cs:1101
_800service.index2.after_Click(Object sender, EventArgs e) in e:\asp.net\800service\index2.aspx.cs:1375
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货