We help IT Professionals succeed at work.

update using  sqlcommandbuilder

KaranGupta asked

I am facing an issue in update query using sqlcommandbuilder class when I check the update command I find this command

UPDATE [subjects1] SET [SubjectCode] = @SubjectCode, [SubjectText] = @SubjectText, [IsSubjectActive] = @IsSubjectActive WHERE (([SubjectID] = @Original_SubjectID) AND ((@IsNull_SubjectCode = 1 AND [SubjectCode] IS NULL) OR ([SubjectCode] = @Original_SubjectCode)) AND ((@IsNull_SubjectText = 1 AND [SubjectText] IS NULL) OR ([SubjectText] = @Original_SubjectText)) AND ((@IsNull_IsSubjectActive = 1 AND [IsSubjectActive] IS NULL) OR ([IsSubjectActive] = @Original_IsSubjectActive)))

but my table only contains the columns SubjectId, SubjectCode,SubjectText and IsSubjectActive from where does rest of the columns came

Karan Gupta
Watch Question

Hi Karan

I'm glad that you able to solve your Insert with the SQL command builder and taking the sample form the querry

 adap.UpdateCommand = cb.GetUpdateCommand(true);
adap.UpdateCommand.Parameters["@SubjectCode"].Value = "SUB1";
adap.UpdateCommand.Parameters["@SubjectText"].Value = "SUB1";
adap.UpdateCommand.Parameters["@IsSubjectActive"].Value = true;


Do you have tried by updating the record with the above format else could you please share to get better understanding for assistance

Top Expert 2015
I suppose that what you call "rest of the columns" are those names starting with @.

They are not columns, they are parameters that will be passed to the procedure when it is executed. When you call Update on your DataTable, those will be replaced by the actual values that needs to be send to the database.