W
Water Cooler v2
Dang! A *simple* query doesn't run on my machine. I wrote a Data Access
Layer (DAL) in a dll that I am testing with the help of a console
application.
Here's the code. I am damn sure that my code is fine. I think my
problem has something to do with MSDAC or some service pack or some
stupid Windows patch missing on my machine.
public static void GetJetScalar()
{
//string SQL = "select [Category Name], [Description] FROM
Categories WHERE [Category ID] = 2";
string SQL = "select [Order ID], [Product] FROM [Order Details]
WHERE [Order ID] = 10248";
DataProvider provider = null;
CategoryShort cat = null;
try
{
provider = new DataProvider();
cat = (CategoryShort)provider.GetScalar(SQL);
if (cat != null)
Console.WriteLine("Name: " + cat.Name + "\n\nDescription: " +
cat.Description);
}
catch(System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
cat = null;
provider = null;
}
}
Here's the code for the GetScalar() implemented by the DataProvider
class:
public System.Object GetScalar(string SQL)
{
System.Object ret = null;
if (this._connection.UnderlyingConnection == null)
{
System.Exception ex = new DatabaseTypeNotSupportedException();
_log.Write(new LogEntry(ex), true);
throw ex;
}
if (this._connection.Database == Databases.MSAccess)
ret = (new OleDbCommand(SQL,
(OleDbConnection)this._connection.UnderlyingConnection)).ExecuteScalar();
else if (this._connection.Database == Databases.SQLServer)
ret = (new SqlCommand(SQL,
(SqlConnection)this._connection.UnderlyingConnection)).ExecuteScalar();
return ret;
}
I get an exception that says: "No value provided for one or more
required parameters." I am trying it on the Northwind database only to
test it. I tried a query two or three queries, all syntactically
correct, but they all yeild the same exception as their result.
Layer (DAL) in a dll that I am testing with the help of a console
application.
Here's the code. I am damn sure that my code is fine. I think my
problem has something to do with MSDAC or some service pack or some
stupid Windows patch missing on my machine.
public static void GetJetScalar()
{
//string SQL = "select [Category Name], [Description] FROM
Categories WHERE [Category ID] = 2";
string SQL = "select [Order ID], [Product] FROM [Order Details]
WHERE [Order ID] = 10248";
DataProvider provider = null;
CategoryShort cat = null;
try
{
provider = new DataProvider();
cat = (CategoryShort)provider.GetScalar(SQL);
if (cat != null)
Console.WriteLine("Name: " + cat.Name + "\n\nDescription: " +
cat.Description);
}
catch(System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
cat = null;
provider = null;
}
}
Here's the code for the GetScalar() implemented by the DataProvider
class:
public System.Object GetScalar(string SQL)
{
System.Object ret = null;
if (this._connection.UnderlyingConnection == null)
{
System.Exception ex = new DatabaseTypeNotSupportedException();
_log.Write(new LogEntry(ex), true);
throw ex;
}
if (this._connection.Database == Databases.MSAccess)
ret = (new OleDbCommand(SQL,
(OleDbConnection)this._connection.UnderlyingConnection)).ExecuteScalar();
else if (this._connection.Database == Databases.SQLServer)
ret = (new SqlCommand(SQL,
(SqlConnection)this._connection.UnderlyingConnection)).ExecuteScalar();
return ret;
}
I get an exception that says: "No value provided for one or more
required parameters." I am trying it on the Northwind database only to
test it. I tried a query two or three queries, all syntactically
correct, but they all yeild the same exception as their result.