I am having an interesting time using the Statement below that reads like this
SqlCommand RiskRevalCommand =
new SqlCommand("select * from CreditAdmin.dbo.CreditData_Test");
I took the SQL statement straight from a query in SQL Server Management Studio, so I know it works in there, but now it causes an exception to be thrown when the program attempts to execute this line:
SqlDataReader reader = RiskRevalCommand.ExecuteReader();
and the error reads:
ExecuteReader: Connection property has not been initialized.
SqlConnection xavierConnection =
new SqlConnection("user id=FB\\user;" +
"password=password;" +
"server=dataserver;" +
"Trusted_Connection=yes;" +
"database=CreditAdmin;" +
"connection timeout=15");
try
{
xavierConnection.Open();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
try
{
SqlCommand RiskRevalCommand = new SqlCommand("select * from CreditAdmin.dbo.CreditData_Test");
SqlDataReader reader = RiskRevalCommand.ExecuteReader();
while (reader.Read())
{
try
{
double.TryParse(reader["Available Balance"].ToString(), out _availability);
...
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
//close the connection
try
{
xavierConnection.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
What should I change about my SQL statement so that It doesn't blow up, and so that I can still do the TryParsing for the fields?
Also how the heck does this break when this works?
(It's what was in the place of the select *
I'm using now)