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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OleDB failing to return data

Status
Not open for further replies.

Craig0201

Technical User
Oct 11, 2000
1,261
GB
Hi,

I have got a problem getting OLEDB to return any data.

The connection is set up as

this.conn = new System.Data.OleDb.OleDbConnection();
//
// conn
//
this.conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\NeuroForm\\Database\\Neuroform.mdb;User Id=admin;Password=;";

The code to get the data is......

public bool checkPKExists(string PK, string TableName)
{
System.Text.StringBuilder builder = new System.Text.StringBuilder();

builder.Append("SELECT [");
builder.Append(TableName);
builder.Append("ID] FROM [");
builder.Append(TableName);
builder.Append("] WHERE [");
builder.Append(TableName);
builder.Append("ID] = ");
try
{
Convert.ToInt32(PK,10);
builder.Append(PK);
}
catch
{
builder.Append("'");
builder.Append(PK);
builder.Append("'");
}
OleDbCommand command = new OleDbCommand(builder.ToString(),conn);

command.CommandType=CommandType.Text;
conn.Open();
int rows = command.ExecuteNonQuery();
conn.Close();
if (rows == 0)
{
return false;
}
else
{
return true;
}
}

This always returns 0. But I can write this query into Access and get a row to return.

Anyone have any ideas what's going wrong?

All help gratefully accepted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top