February 15, 2010 at 11:46 am
public DataTable GetPublisherByName(string name)
{
SqlConnection connection = new SqlConnection(connectionString);
DataTable rowTable = new DataTable();
try
{
//ArrayList list = new ArrayList();
string commandText =
@"SELECT pub_id, pub_name FROM dbo.publishers WHERE pub_name = @name;";
SqlParameter param = new SqlParameter();
param.ParameterName = "@name";
param.Value = name;
using (SqlCommand command = new SqlCommand(commandText, connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
DataRow row = rowTable.NewRow();
row["pub_id"] = reader["pub_id"];
row["pub_name"] = reader["pub_name"];
row["city"] = reader["city"];
row["state"] = reader["state"];
row["country"] = reader["country"];
rowTable.Rows.Add(row);
}
return rowTable;
}
}
}
catch (Exception ex)
{
throw new Exception("UnexpectedSql Exception Encountered" + "" +ex.Message
+ "" + ex.StackTrace);
}
finally
{
connection.Close();
}
}
The above code gives a SqlException whenever the command.ExecuteReader statement is executed, but so far I have not been able to get any useful information out of the exception to try to determine why its failing. I would appreciate any help diagnosing this problem. Thanks.
February 15, 2010 at 12:28 pm
You posted this in the SQL 2008 forum. Please do NOT cross-post!!!
Redirect here . . .
+--------------------------------------------------------------------------------------+
Check out my blog at https://pianorayk.wordpress.com/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply