Access SQL update fra Visual Studio
Hej, jeg har et problem med min SQL Update kode.Jeg vil opdatere min database med input fra commandprompten ved at soege via indikatoren id.
//not working - something wrong with SQL command!
public static void updateInDB()
{
try
{
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; " + @"Data source=C:\temp\products.mdb";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = new OleDbCommand();
//Jeg tror at problemet ligger i nedestående linje:
command.CommandText = "UPDATE [name] AND [price] SET [name] = ?, [price] = ?, WHERE [id] = ?";
command.Connection = connection;
//Search id to select the item to update!
//the id should be attributed automatically
Console.Write("Enter an id to update a product: ");
string id = Console.ReadLine();
command.Parameters.AddWithValue("@id", id);
//Enter artist and album name separeted by a comma: ",".
Console.Write("Enter new name to update it: ");
string name = Console.ReadLine();
command.Parameters.AddWithValue("@name", name);
Console.Write("Enter a new price for the product: ");
string price = Console.ReadLine();
command.Parameters.AddWithValue("@price", price);
command.ExecuteNonQuery();
connection.Close();
}
catch (Exception e)
{
Console.WriteLine("Error in inserting new data!" + e.ToString());
}
}
}}