I a Parameter ordial = 1 error on this code.
Can anyone explain it in this context? dbCon is correct as I can insert data to the database just trying out how to get it back no.
if (dbCon.State == ConnectionState.Closed)
{
dbCon.Open(); ;
}
SqlCeParameter vetidfromdropbox = new SqlCeParameter("@vetidfromdropbox", SqlDbType.Int);
vetidfromdropbox.Value = 2;
SqlCeCommand mySQLCommand = new SqlCeCommand("SELECT * FROM vets WHERE vetID = @vetidfromdropbox", dbCon);
SqlCeDataReader rdata = mySQLCommand.ExecuteReader();
if(rdata.Read()){
editNameTextbox.Text = (String)rdata["vetName"];
editSurnameTextbox.Text = (String)rdata["vetSurname"];
editCompanyNameTextbox.Text = (String)rdata["vetCompanyName"];
editPractiseAddTextBox.Text = (String)rdata["vetPractiseAddress"];
editMobileTextbox.Text = (String)rdata["vetMobile"];
editOtherTextbox.Text = (String)rdata["vetOther"];
editNotesTextbox.Text = (String)rdata["vetNotes"];
}else{
MessageBox.Show(" There has been an error with Read() ");
}
if (dbCon.State == ConnectionState.Open)
{
dbCon.Close();
}
You didn’t add parameter to your SQL command:
You can use AddWithValue to simplify the syntax:
Side note: use
usingon your sql connection and command to guarantee disposal and to simplify code.