我創建返回一個數據表中的類,但是它顯示一個錯誤如何創建在c#中返回數據表的類?
錯誤1「demo_C_Sharp.Cls_onnection.GetApprovedData(參照字符串)」:不是所有的代碼路徑返回一個值d:\的Vivek \ demoproject \演示升C \演示升C \ class文件\ Cls_onnection.cs 45 26演示升C
我創建了以下方法:
public DataTable GetApprovedData(ref string tablename)
{
try
{
if (cnn.State==System.Data.ConnectionState.Closed)
{
dtTbl = new DataTable();
cnn.Open();
cmd = new SqlCommand("USP_Billing_GetApprovedData", cnn);
cmd.CommandTimeout = 5000;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ProcessName", tablename);
da = new SqlDataAdapter(cmd);
da.Fill(dtTbl);
return dtTbl;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
可能重複的[不是所有的代碼路徑返回值,而使用Try Catch](http://stackoverflow.com/questions/36578334/not-all-code-paths-return-value-while-using-try-catch ) – quetzalcoatl