请教 “System.Data.SqlClient.SqlException”类型的异常在 System.Data.dll 中发生,但未在用户代码中进行处理
司徒傀儡 2016-06-25 05:30:53 红色的为报错的地方,找个好久不知道怎么改,服务启动了,允许远程连接 / VS2015 SQL 2012
public void DLClassBind(DataList dlName)
{
string P_Str_SqlStr = "select * from Class";
SqlConnection myConn = dbObj.GetConnection();
SqlDataAdapter da = new SqlDataAdapter(P_Str_SqlStr, myConn);
DataSet ds = new DataSet();
da.Fill(ds, "Class");
dlName.DataSource = ds.Tables["Class"].DefaultView;
dlName.DataBind();
}
/// <summary>
/// 绑定图书信息(精品推荐 热销图书 打折图书)
/// </summary>
/// <param name="P_Int_Deplay">(精品推荐 热销图书 打折图书)三种类别的标志</param>
/// <param name="P_Str_srcTable">表信息</param>
/// <param name="DLName">绑定控件名</param>
public void DGIBind(int P_Int_Deplay, string P_Str_srcTable, DataList DLName)
{
SqlConnection myConn = dbObj.GetConnection();
SqlCommand myCmd = new SqlCommand("Pr_DeplayBookInfo", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
//添加参数
SqlParameter Deplay = new SqlParameter("@Deplay", SqlDbType.Int, 4);
Deplay.Value = P_Int_Deplay;
myCmd.Parameters.Add(Deplay);
//执行过程
myConn.Open();
try
{
myCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
myCmd.Dispose();
myConn.Close();
}
SqlDataAdapter da = new SqlDataAdapter(myCmd);
DataSet ds = new DataSet();
da.Fill(ds, P_Str_srcTable);
DLName.DataSource = ds.Tables[P_Str_srcTable].DefaultView;
DLName.DataBind();
}