Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Problem Adding New record to data Grid

Hi

I have quick question . I have a VB.net form where I have one drop down combo box ,a data grid ,and two button . A user will choose the value from the drop down list box and relivant information will show on the data grid . This part is working fine . But I have to let the user add new record to the data grid and they will able to press update button which will save the information to the SQL Server database . But I can not add new data to the data grid . The error I am getting is Set Identity is off . I can delete the information from the data grid . How to solve this problem . I have made the primary key column as Identity column and increment by one everyt time you add new data .

Thanks
[720 byte] By [software_develo] at [2007-11-11 8:45:15]
# 1 Re: Problem Adding New record to data Grid
Sounds like you're trying to insert an explicit value for the identity column. You can't do that (unless you set INSERT_IDENTITY to off); you should allow the database to generate identity values automatically. Edit your INSERT query to omit the identity column and value.
Phil Weber at 2007-11-11 21:47:07 >
# 2 Re: Problem Adding New record to data Grid
Hi

Thanks for the reply . I want the identity value to generate automatically . I have a filed called ID which is the primary key in the SQL table . The value for this field should generate automatically as this is a identity field . In the data grid when I try to add new record a new empty row is automativally added with NULL value . I can put the values in the empty rows but the value for the ID field should generate automatically . But it is not working . What I have to do . I do not have any insert statement .I am using select statement to get the data in the data grid .

Thanks
software_develo at 2007-11-11 21:48:02 >
# 3 Re: Problem Adding New record to data Grid
Hi,

Build your own DataTable --need to store data that has a table-like structure.
This DataTable is used for programming the grid for accepting the multiple rows of data in the form.

Instantiating Dataable object
Create Table structure ( order of data acceptance in the datagrid)
Add column to datatable structure
Add column to pk array
Set primary key
Add column to data table structure
Then you bind the grid to this table. So, actually your data will be stored in the DataTable before saving into the SQL Server.
After user confirms the inserting, you call the stored procedure to save the data.

Regards
Bhar
http://www.vkinfotek.com
Bharati at 2007-11-11 21:49:00 >