Use Parameters.AddWithValue as shown below
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Password=RainbowTrout;"; InsertQry = "Insert into Sections(Name, PartNumber, VersionNumber, Channel, Address, Status, IPAddr) " + "values(@SectionName, @PartNumber, @VersionNumber, @Channel, @Address, @Status, @IPAddr)"; NewCfgConnection.ConnectionString = string.Format(connectionString, ConfigFN); NewCfgCommand.Connection = NewCfgConnection; NewCfgCommand.CommandText = InsertQry; NewCfgConnection.Open(); // Clear parameter values from last record NewCfgCommand.Parameters.Clear(); // Insert record into sections table - set parameters NewCfgCommand.Parameters.AddWithValue("@SectionName", sSectionName); NewCfgCommand.Parameters.AddWithValue("@PartNumber", sPartNumber); NewCfgCommand.Parameters.AddWithValue("@VersionNumber", sVersionNumber); NewCfgCommand.Parameters.AddWithValue("@Channel", iChannel); NewCfgCommand.Parameters.AddWithValue("@Address", iAddress); NewCfgCommand.Parameters.AddWithValue("@Status", iStatus); NewCfgCommand.Parameters.AddWithValue("@IPAddr", iIP); NewCfgCommand.ExecuteNonQuery();
source share