I have a Winforms application with a SQL Server CE 3.5 database. I want to do an UPDATE
query and for this I need a SELECT
query.
Here's what I wrote:
string command1 = "SELECT Column1, Column2, Column3 FROM Table1";
string command2 = "UPDATE Table2 SET Column2 = @var2, Column3 = @var3 WHERE Column1 = @var1";
using (SqlCeCommand cmd1=new SqlCeCommand(command1, connection))
{
SqlCeDataReader reader;
reader = cmd1.ExecuteReader();
while (reader.Read())
{
int var1 = (int)reader[0];
int var2 = (int)reader[1];
string var3 = (string)reader[2];
SqlCeCommand cmd2= new SqlCeCommand (command2, connection);
cmd2.ExecuteReader();
}
}
I get an error
A parameter is missing. Parameter ordinal=3
You have three parameters in your second command (
command2
) - but you never define those parameters, nor do you set any values for them to use!Try this code: