我在Dataset
中填充了一些值,但是当我不返回任何行时,我为那些返回的值小于0的东西做了其他部分。
这是代码
ds = GetCircleDetails(XY, txtSapIdNHQCircle.Text);
if (ds.Tables[0].Rows.Count > 0)
{
strState = ds.Tables[0].Rows[0]["R4GSTATENAME"].ToString();
if (Save(0))
{
BindDetails(false);
}
}
else
{
//ClientScript.RegisterStartupScript(Page.GetType(), "erroralert", "checkRdValueForSingle('Please enter valid Lat/Long to submit the details')", true);
string latLongMes = "alert('Please enter valid Lat/Long to submit the details')";
ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", latLongMes, true);
txtLatNHQCircle.Value = "";
txtLongNHQCircle.Value = "";
ClientScript.RegisterStartupScript(Page.GetType(), "erroralert", "checkRdValueForSingle('')", true);
return;
}
if (lblStateNHQCircle.Text != strState)
{
ClientScript.RegisterStartupScript(Page.GetType(), "erroralert", "checkRdValueForSingle('The entered lat/long is out of the existing State i.e., so could not save the record.');", true);
return;
}
}
else
{
if (Save(0))
{
BindDetails(false);
}
}
}
else if(Save(0))
{
BindDetails(false);
}
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(Page.GetType(), "erroralert", "alert('Error occured: Could not save change request data.');", true);
ErrorLog.Save(ex.Message, ex.StackTrace, "ChangeRequestDetails - btnSave_Click", CurrentUserName);
throw ex;
}
GetCircleDetails(XY, txtSapIdNHQCircle.Text);
的功能在下面
public DataSet GetCircleDetails(string xyCoordinate, string sapid)
{
string ConnectionStringWFM = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringCR"].ConnectionString;
DataSet ds = new DataSet();
OracleConnection oraConn = new OracleConnection(ConnectionStringWFM);
string strStoreProcedure = "GET_CIRCLENAME_XYPOINT";
try
{
OracleCommand cmd = new OracleCommand(strStoreProcedure, oraConn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OracleParameter("P_XYCORDINATE", xyCoordinate));
cmd.Parameters.Add(new OracleParameter("P_SAPID", sapid));
cmd.Parameters.Add(new OracleParameter("OUTR4GSTATENAME", OracleDbType.RefCursor, ParameterDirection.Output));
cmd.Parameters.Add(new OracleParameter("OUTALLDETAILS", OracleDbType.RefCursor, ParameterDirection.Output));
if (oraConn.State == ConnectionState.Closed) oraConn.Open();
OracleDataAdapter da = new OracleDataAdapter(cmd);
da.Fill(ds);
return ds;
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
请提出为什么要在catch
而不是else
更新
我收到错误消息
ClientScript.RegisterStartupScript(Page.GetType(), "erroralert", "alert('Error occured: Could not save change request data.');", true);
但是我应该把它当作
string latLongMes = "alert('Please enter valid Lat/Long to submit the details')";
ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", latLongMes, true);
答案 0 :(得分:0)
要检查数据集是否为空,必须检查null和表计数。可以使用if(ds != null && ds.Tables.Count > 0 )
答案 1 :(得分:-1)
如果您在
中遇到错误ClientScript.RegisterStartupScript
添加此代码
Responce.Write("<script>alert('Your Text Here');</script>")