Getting error for the simple code Please help me out.
Thank you

I have a textbox and one table. Once the user enters data in the textbox & click save button, the data gets saved to database. I've written following code but I'm getting following error. Please help me out. Thank you

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'Dim ds As DataSet

If tbxNote.Text <> String.Empty Then
Dim NoteRow As ChemComp_adminDS.GeneralNotesRow = m_ccDb.Chemcomp_adminDS.GeneralNotes.NewGeneralNotesRow
'Dim crow As DataRow = ds.Tables("GeneralNotes").Rows(0)
'User entered comment for this susbstanceID for the first time so new row to be inserted in
'to AdminComment table

' NoteRow.NoteID = CInt(NoteRow.Item("NoteId"))
NoteRow.CreatedBy = My.User.Name
NoteRow.CreatedOn = Now
NoteRow.ModifiedBy = My.User.Name
NoteRow.ModifiedOn = Now
NoteRow.Note = tbxNote.Text.Trim()
m_ccDb.InsertRow(NoteRow)
End If
'm_ccDb.GetList(m_ccDb.Chemcomp_adminDS.GeneralNotes)

End Sub

End Class
at the time of insertrow function iam getting the following error.

Cannot insert explicit value for identity column in table 'GeneralNotes' when IDENTITY_INSERT is set to OFF.
Member Avatar for pilsdumps

It looks like you're using SQL Server as your database platform. If so, the error message you're receiving suggests that you're trying to insert a value into an identity column. Your insert statement should not include the identity field as this value is created automatically by SQL based on your seed and increment settings for the field in question.

If you want to force an value in an identity column, you have to run

set identity_insert [GeneralNotes] on

first.

Don't forget to turn it off again if you want the identity field to be useful. To look for the identity field, run sp_help GeneralNotes.

It looks like you're using SQL Server as your database platform. If so, the error message you're receiving suggests that you're trying to insert a value into an identity column. Your insert statement should not include the identity field as this value is created automatically by SQL based on your seed and increment settings for the field in question.

If you want to force an value in an identity column, you have to run

set identity_insert [GeneralNotes] on

first.

Don't forget to turn it off again if you want the identity field to be useful. To look for the identity field, run sp_help GeneralNotes.

Thank you so much for your suggestion!!!!

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.