Shrivallabh
Shrivallabh

Reputation: 2903

Error while updating in database using dataset

While running the below code getting this error

Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

Tried doing many things nothing is working. Below is the code

 string queryUp = "SELECT Node_A_ObjectID,Node_Z_ObjectID FROM NDDILinks";
            string myConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\TiptonDB.mdb";
            DataSet dtup = new DataSet();
            using (OleDbConnection myConnection = new OleDbConnection())
            {
                myConnection.ConnectionString = myConnectionString;
                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = myConnection;
                myConnection.Open();
                OleDbDataAdapter adp = new OleDbDataAdapter(queryUp, myConnection);
                adp.FillSchema(dtup, SchemaType.Source, "NDDILinks");
                adp.Fill(dtup, "NDDILinks");

                dtup.Tables[0].Rows[1][0] = 2350;
                adp.AcceptChangesDuringUpdate = true;

                OleDbCommandBuilder objCommandBuilder = new OleDbCommandBuilder(adp);
                cmd.Parameters.Add("@Node_A_ObjectID", OleDbType.Integer, sizeof(int), "Node_A_ObjectID");
                int a1 = adp.Update(dtup, "NDDILinks");
                dtup.AcceptChanges();

Upvotes: 0

Views: 140

Answers (1)

Habib
Habib

Reputation: 223422

I am not selecting primary key only 2 values Node_A_ObjectID,Node_Z_ObjectID.Do i need to select primary key also ?

Based on your comment on the post. You must select the Primary key for your UPDATE to work with the dataset, or you can specify your own UPDATE or INSERT query. You may also see this discussion on MSDN

Upvotes: 2

Related Questions