详细信息 在位置 0 处没有任何行。
出错的页面代码
public partial class CompanyDecision_CD_Info : System.Web.UI.Page
{
WebService webService = new WebService();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] == null || Session["UserLevel"] == null)
{
Response.Redirect("~/Error.aspx");
}
this.tbContent.Style.Add("OverFlow","hidden");
string strID = Request.QueryString["cdid"];
string strSql = "Select z_CompanyDecision.CD_ID,z_CompanyDecision.CD_Title,z_CompanyDecision.CD_IsConfirm, z_CompanyDecision.CD_AddDate, z_CompanyDecision.CD_Content, z_Person.Person_ID, z_CompanyDecision.CD_AddPersonID, z_Person.Person_RealName FROM z_CompanyDecision INNER JOIN z_Person ON z_CompanyDecision.CD_AddPersonID = z_Person.Person_ID where CD_ID='" + strID + "';";
DataTable table = webService.ExcuteSelect(strSql);
this.lblID.Text = strID;
this.lblTitle.Text = table.Rows[0]["CD_Title"].ToString();
this.lblAuther.Text = table.Rows[0]["Person_RealName"].ToString();
this.tbContent.Text = table.Rows[0]["CD_Content"].ToString();
this.lblAddDate.Text = table.Rows[0]["CD_AddDate"].ToString();
if (table.Rows[0]["CD_IsConfirm"].ToString() == "False")
{
Response.Redirect("~/Error.aspx");
}
}
}
出错的页面代码
public partial class CompanyDecision_CD_Info : System.Web.UI.Page
{
WebService webService = new WebService();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] == null || Session["UserLevel"] == null)
{
Response.Redirect("~/Error.aspx");
}
this.tbContent.Style.Add("OverFlow","hidden");
string strID = Request.QueryString["cdid"];
string strSql = "Select z_CompanyDecision.CD_ID,z_CompanyDecision.CD_Title,z_CompanyDecision.CD_IsConfirm, z_CompanyDecision.CD_AddDate, z_CompanyDecision.CD_Content, z_Person.Person_ID, z_CompanyDecision.CD_AddPersonID, z_Person.Person_RealName FROM z_CompanyDecision INNER JOIN z_Person ON z_CompanyDecision.CD_AddPersonID = z_Person.Person_ID where CD_ID='" + strID + "';";
DataTable table = webService.ExcuteSelect(strSql);
this.lblID.Text = strID;
this.lblTitle.Text = table.Rows[0]["CD_Title"].ToString();
this.lblAuther.Text = table.Rows[0]["Person_RealName"].ToString();
this.tbContent.Text = table.Rows[0]["CD_Content"].ToString();
this.lblAddDate.Text = table.Rows[0]["CD_AddDate"].ToString();
if (table.Rows[0]["CD_IsConfirm"].ToString() == "False")
{
Response.Redirect("~/Error.aspx");
}
}
}
{
string strConn = @"Data Source = HQCHEN\SQLEXPRESS; Initial Catalog = OfficeOnline;User ID=sa;Password=8295011";
DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
DbConnection dbConn = dbProviderFactory.CreateConnection();
dbConn.ConnectionString = strConn;
dbConn.Open();
DbCommand dbComm = dbProviderFactory.CreateCommand();
dbComm.Connection = dbConn;
dbComm.CommandText = strSql;
DbDataReader reader = dbComm.ExecuteReader();
return reader.Read();
}
public void ExcuteSql(string strSql)
{
string strConn = @"Data Source = HQCHEN\SQLEXPRESS;Initial Catalog = OfficeOnline;User ID=sa;Password=8295011";
DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
DbConnection dbConn = dbProviderFactory.CreateConnection();
dbConn.ConnectionString = strConn;
dbConn.Open();
DbCommand dbComm = dbProviderFactory.CreateCommand();
dbComm.Connection = dbConn;
dbComm.CommandText = strSql;
dbComm.ExecuteNonQuery();
dbConn.Close();
dbConn.Dispose();
}
public DataTable ExcuteSelect(string strSql)
{
string strConn = @"Data Source = HQCHEN\SQLEXPRESS;Initial Catalog = OfficeOnline;User ID=sa;Password=8295011";
DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
DbConnection dbConn = dbProviderFactory.CreateConnection();
dbConn.ConnectionString = strConn;
dbConn.Open();
DbCommand dbComm = dbProviderFactory.CreateCommand();
dbComm.Connection = dbConn;
dbComm.CommandText = strSql;
DbDataAdapter adapter = dbProviderFactory.CreateDataAdapter();
adapter.SelectCommand = dbComm;
DataSet dsDataSet = new DataSet();
adapter.Fill(dsDataSet, "table");
return dsDataSet.Tables["table"];
}
感觉是 返回的记录为空应该做下判断 table .Rows.Count>0将sql语句调试 输入 ,在数据库里查询看一下。
异常详细信息: System.Data.SqlClient.SqlException: 已成功与服务器建立连接,但是在登录过程中发生错误。 (provider: 共享内存提供程序, error: 0 - 管道的另一端上无任何进程。)只是有的时候出这个错,不知道什么原因哦?