Hello,

I'm having some trouble with SQL CE.

The below code *should* insert a record into the 'maps' table. (table adapters all set up)

sometimes it says cannot insert as breaching primary key constraint, which is fine, but it otherwise fails with cannot insert NULL into iMapId. I have checked and txtNumber.Text.ToString is not null, and I've even tried explicitly setting newMap["iMapId"] equal to some integer and it still complains that it's null.

try
            {
                DataRow newMap = mapappdbDataSet.maps.NewRow();
                newMap["iRegionId"] = Convert.ToInt16(cmbRegion.SelectedValue);
                newMap["vMapName"] = txtMapNAme.Text.ToString();
                newMap["iMapId"] = txtNumber.Text.ToString();


                mapappdbDataSet.maps.Rows.Add(newMap);
                mapsTableAdapter.Update(newMap);
                mapappdbDataSet.AcceptChanges();

                this.Close();
            }
            catch (Exception excp)
            {
                MessageBox.Show("That didnt work. Heres the message: " + excp.Message.ToString());
            }

Any ideas at all?

Thanks

OK I just realised that the table USED to have an auto-incremental field for iMapId and I hadn't updated the tableadapter since.

what a silly billy....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.