In short, C # throws me "Dynamic SQL generation for UpdateCommand is not supported in relation to SelectCommand, which does not return key column information", while the table in question has a primary key (Identity, since it is MSSQL).
My code is as follows:
void loaddata()
{
try
{
DS = new DataSet();
sqladapt = new SqlDataAdapter("SELECT servicetag,name,defect,primkey FROM " + Properties.Settings.Default.DBtableLaptops + "", sqlcon);
sqladapt.FillSchema(DS, SchemaType.Source);
sqladapt.Fill(DS);
commandBuilder = new SqlCommandBuilder(sqladapt);
DT = DS.Tables[0];
Laptops_datagridview.DataSource = DT;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void savedata()
{
try
{
sqladapt.Update(DS);
sqladapt.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Data loading, etc. works great, adds newlines and saves them. But whenever I update or delete a line, it throws an error. Primkey is my primary key, it is an automatically increasing integer.
Google, , , , , , .
, 6 .
EDIT:
create :
CREATE TABLE [dbo].[laptopregistratieDB_laptops](
[Servicetag] [text] NOT NULL,
[Name] [text] NOT NULL,
[Defect] [bit] NOT NULL,
[primkey] [int] IDENTITY(1,1) NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]