First insert ignore adding records to Access
-
Using the following code the first insert is ignored so only the 'y' and 'z' rows appear in the table. The table is empty before any of the inserts. Anybody know why this is happening? Is there an easier way of getting data into a table?
OleDbConnection cn = new OleDbConnection(); cn.ConnectionString = @"Provider=Microsoft.JET.OLEDB.4.0;" + @"Data Source=" + sDBPath + ";" + @"Jet OLEDB:Engine Type=5"; cn.Open(); // OleDbDataAdapter adap = new OleDbDataAdapter("SELECT * FROM Info",cn); OleDbCommand cmdInsert = new OleDbCommand(); cmdInsert.Connection = cn; cmdInsert.CommandText = @"INSERT INTO Info (InfoDesc, InfoVal) VALUES (?, ?)"; cmdInsert.Parameters.Add(new OleDbParameter("InfoDesc",OleDbType.VarWChar,50,"InfoDesc")); cmdInsert.Parameters.Add(new OleDbParameter("InfoVal",OleDbType.VarWChar,50,"InfoVal")); adap.InsertCommand = cmdInsert; DataSet ds = new DataSet(); adap.Fill(ds,"Info"); DataRow dr = null; dr = ds.Tables[0].NewRow(); dr["InfoDesc"] = "x"; dr["InfoVal"] = "x"; ds.Tables[0].Rows.Add(dr); dr = ds.Tables[0].NewRow(); dr["InfoDesc"] = "y"; dr["InfoVal"] = "y"; ds.Tables[0].Rows.Add(dr); dr = ds.Tables[0].NewRow(); dr["InfoDesc"] = "z"; dr["InfoVal"] = "z"; ds.Tables[0].Rows.Add(dr); adap.Update(ds,"Info"); ds.Dispose(); // cn.Close();>
Rugby League: The Greatest Game Of All.