Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query fails in C# with field "bit_length" 1

Status
Not open for further replies.

sammye

Programmer
Oct 5, 2007
35
US
Does anyone have an idea why the query below results in an error? The problem appears to be centered around the field named "bit_length". If I use query for only "name" or "*" instead, the query returns just fine.

Error:
failed to retrieve the required data from the database. ierrorinfo.getdescription failed with E_FAIL

Code:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=myDb.mdb;User Id=admin;Password=;";

string sQuery = "SELECT bit_length FROM my_data";

Database table structure:
name = text
bit_length = number
 
Can you post the remainder of your code?

How you are trying to execute the query and what not...

Good Luck

Alex

[small]----signature below----[/small]
I can't compete with you physically, and you're no match for my brains.
You're that smart?
Let me put it this way. Have you ever heard of Plato, Aristotle, Socrates?
Yes.
Morons!
 
Sure, here's the code:

{
OleDbConnection cnn = null;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;User Id=admin;Password=;";

string sQuery = "SELECT * FROM my_data";
//string sQuery = "SELECT *, bit_length FROM my_data";

// Create the dataset and add the Categories table to it:
DataSet dataset = new DataSet();
try
{
cnn = new OleDbConnection(connectionString);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(String.Format("Error: Failed to create a database connection. \n{0}", ex.Message));
return;
}

try
{
OleDbCommand cmd = new OleDbCommand(sQuery, cnn);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(cmd);

cnn.Open();
dataAdapter.Fill(dataset, "my_data");
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(String.Format("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message));
return;
}
finally
{
cnn.Close();
}

// all into an array:
DataTableCollection dta = dataset.Tables;

List<string> parameters = new List<string>();
try
{
DataRowCollection dra = dataset.Tables["my_data"].Rows;
textBox1.Text = dataset.Tables["my_data"].Columns[0].ColumnName + " " + dataset.Tables["my_data"].Columns[1] + " " + dataset.Tables["my_data"].Columns[2] + "\r\n";
foreach (DataRow dr in dra)
{
//parameters.Add(dr["name"].ToString() + int.Parse(dr["start_bit"].ToString()) + int.Parse(dr["bit_length"].ToString()));
parameters.Add(dr[0].ToString() + " " + int.Parse(dr[1].ToString()) + " " + int.Parse(dr[2].ToString()));
textBox1.Text += parameters[parameters.Count - 1] + "\r\n";
}

}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(String.Format("Error accessing param_info: {0}", ex.ToString()));
}
}
 
try putting BIT_LENGTH in square brackets.

Code:
[BIT_LENGTH]

bit_length is a function on some database platforms, and I suppose is treated specially by ADO.net.

Hope this helps,

Alex

[small]----signature below----[/small]
I can't compete with you physically, and you're no match for my brains.
You're that smart?
Let me put it this way. Have you ever heard of Plato, Aristotle, Socrates?
Yes.
Morons!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top