Adding New Records

Bob721

Member
Joined
Oct 15, 2007
Messages
6
Programming Experience
Beginner
Using VB.NET 2003 connected to a SQL Server database I'm creating an application that collects the results of a survey. So far it’s able to display and move through the pre-existing records, but I'm unable to create new records. Using the code below, when the "New Survey" button is clicked a new record appears in the database but the application doesn’t move to the new record and let me enter information. When I look at the database after trying to enter a new survey, I see the new row but it’s grayed out and is inaccessible from the application.

VB.NET:
Private Sub NewSurvey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewSurvey.Click
Me.BindingContext(DsSurvey1, "survey_tbl").AddNew()
End Sub

Does anyone know why this is happening and what I need to do to resolve it? Thanks!
 
Last edited by a moderator:
Hi, i am fairly new to vb but from projects i have built the following code worked fine.

For example if you have a survey with the bindingsource named surveybindingsource, the tableadapter named surveytableadapter and the dataset named as dsSurvey1

When adding i would use:
VB.NET:
me.surveybindingsource.addnew()

When saving i would use

VB.NET:
me.surveybindingsource.endedit()
me.surveytableadapter.update(me.dsSurvey.survey_tbl)

Give it a try it works fine for me
 
Hi, i am fairly new to vb but from projects i have built the following code worked fine.

For example if you have a survey with the bindingsource named surveybindingsource, the tableadapter named surveytableadapter and the dataset named as dsSurvey1

He's using .NET 1.1, bindingsource does not exist because it was new in .NET 2.0..
 
Ahh, didnt know bindingsources and tableadapters were new to 2.0, i have only used 2.0, i will look for that before posting in future.

Apologies if i confused you bob721
 
That code doesn't add anything to any database. It simply adds a new item to your bound list, which is presumably a DataView. You still need to call EndCurrentEdit to add it to the DataTable, and it still only exists locally, not in the database.

Where exactly is this record of yours greyed out? Are you talking about in a DataGrid?
 
The record is greyed out when I preview the data in the dataset for the SQLDataAdapter. Then when I look at the new record on the actual SQL Server (Enterprise Manager), all the columns are null except the first column which is the auto-number id.
 
Back
Top