Hullo,
I have a quite simple piece of code that returns a syntax error in the query execution: Have you got any idea about what might be wrong?
I have a quite simple piece of code that returns a syntax error in the query execution: Have you got any idea about what might be wrong?
Code:
public void SQLCommandWithParam(string name, byte[] image)
{
OleDbCommand sqlCommand1 = new OleDbCommand();
System.Data.OleDb.OleDbConnection myOleConnection = new System.Data.OleDb.OleDbConnection();
myOleConnection.ConnectionString=connectionString();
myOleConnection.Open();
sqlCommand1.Connection = myOleConnection;
try
{
if (sqlCommand1.Parameters.Count ==0 )
{
sqlCommand1.CommandText = "INSERT INTO Image (Name, Immagine) " +
"VALUES(@Name, @Picture);";
sqlCommand1.Parameters.Add("@Name",
System.Data.OleDb.OleDbType.VarChar, 200);
sqlCommand1.Parameters.Add("@Picture",
System.Data.OleDb.OleDbType.Binary);
}
sqlCommand1.Parameters["@Name"].Value = name;
sqlCommand1.Parameters["@Picture"].Value = image;
sqlCommand1.Connection = myOleConnection;
int iresult=sqlCommand1.ExecuteNonQuery();
MessageBox.Show(Convert.ToString(iresult));
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Comment