M
MarkusR
If I run the stored proc in the Query Analyzer this works and I get the
expected result set back. However when I run it in my application I get
a results set of one row but when I try to access the values I get
"Invalid attempt to read when no data is present".
private void GetLotIDPriorityFromLot(string aLotDesc, out int aLotID,
out DateTime aPriorityDate)
{
SqlConnection Conn;
SqlDataReader reader = null;
aLotID = 0;
aPriorityDate = DateTime.Today;
Conn = new SqlConnection("user id=myuserid;"
+"password=mypwd;"
+"server=myserver;"
+"database=mydatabase;"
+"connection timeout=30");
Conn.Open();
try
{
SqlCommand cmd =
new SqlCommand("sp_GetLotIDPriorityFromLot",
Conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@lot", aLotDesc));
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
---> aLotID =
Convert.ToInt32(reader[0].ToString());
aPriorityDate =
Convert.ToDateTime(reader[1].ToString());
}
}
finally
{
if (reader != null)
reader.Close();
if (Conn != null)
Conn.Close();
}
}
Any thoughts?
-Markus_R
expected result set back. However when I run it in my application I get
a results set of one row but when I try to access the values I get
"Invalid attempt to read when no data is present".
private void GetLotIDPriorityFromLot(string aLotDesc, out int aLotID,
out DateTime aPriorityDate)
{
SqlConnection Conn;
SqlDataReader reader = null;
aLotID = 0;
aPriorityDate = DateTime.Today;
Conn = new SqlConnection("user id=myuserid;"
+"password=mypwd;"
+"server=myserver;"
+"database=mydatabase;"
+"connection timeout=30");
Conn.Open();
try
{
SqlCommand cmd =
new SqlCommand("sp_GetLotIDPriorityFromLot",
Conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@lot", aLotDesc));
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
---> aLotID =
Convert.ToInt32(reader[0].ToString());
aPriorityDate =
Convert.ToDateTime(reader[1].ToString());
}
}
finally
{
if (reader != null)
reader.Close();
if (Conn != null)
Conn.Close();
}
}
Any thoughts?
-Markus_R