nathan

nathan

  • NA
  • 15
  • 0

OleDb problems returning single records

Nov 16 2006 6:35 AM
Hi guys, hopefully someone can help me with this one. I have no problems getting a table of data into a dataGrid. My problem is that i can't get a SELECT statement to return just one record.
I think my problem lies with the dataAdapter because i can successfully add,delete and update records BUT they don't appear, added,deleted or updated until i close and reopen the program and reload the table into the datagrid. Therefore i feel it's something to do with updating the dataSet????

I'm trying to return a single record from a search using a textBox. Can anyone confirm that this
code should work...

string select =
"SELECT Name,Address1,Address2,Address3,PostCode FROM Churches "+
"WHERE PostCode = '" + txtPostCode.Text +"'";

updateCmd.CommandText = select;

updateCmd.Connection = updateConn;

updateCmd.Parameters.Add("name",OleDbType.Char,255,"Name").Value = "";
updateCmd.Parameters.Add("address1",OleDbType.Char,255,"Address1").Value = "";
updateCmd.Parameters.Add("address2",OleDbType.Char,255,"Address2").Value = "";
updateCmd.Parameters.Add("address3",OleDbType.Char,255,"Address3").Value = "";
updateCmd.Parameters.Add("postCode",OleDbType.Char,255,"PostCode").Value =txtPostCode.Text;

updateConn.Open();

try

{

cmd.ExecuteNonQuery();
//is there some i should have here to get the new single record displayed onto the dataGrid????

}

catch (OleDbException e1)

{

MessageBox.Show(e1.ToString());

}
updateConn.Close();
updateCmd.Parameters.Clear();
}

It would solve so many headaches if i knew the missing code. I get no errors by the way, so i know the query is passing, i've even had the query pass returned to check it.

Any help is appreciated very much, thanks guys