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.
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.