Empty Dataset Connected to Database for Insert


Please can you give me some advice how I can create an empty dataset that is connected to a database so that I can insert NEW records into the dataset table and then save them to the database, allowing the user to UPDATE\DELETE the NEW record if required (after the initial INSERT).

Would I need to create a SELECT statement to the database table that returns 0 rows (e.g. SELECT ... ... WHERE ID = 0) to build a blank dataset with populated column names?

Basically I would like the user to open a blank form and create a new record, I understand I could simply do an INSERT command within the form but this would not allow me to bound the fields and UPDATE\DELETE the record after the initial insert.

Thanks, Greg
Who is Participating?
CodeCruiserConnect With a Mentor Commented:
But if you want to go the dataset route then your approach of running a select command to return 0 rows would work.
Ess KayEntrapenuerCommented:
Create a class to hold the data, when you click add new button, save all the the textboxes into a copy of the class using the function below

Then run an insert statement from the class which basically send the data to a stored procedure in your database

Private Sub InsertRecord()
            objclassBLAH.Fields("ID").Value = IsEmptyString(txtclsobjclassBLAH_ID.Text, Null)
            objclassBLAH.Fields("Name").Value = IsEmptyString(txtclsobjclassBLAH_NAME.Text, Null)
            objclassBLAH.Fields("Phone").Value = IsEmptyString(txtclsobjclassBLAH_PHONENUMBER.Text, Null)

            objclassBLAH.InsertObject(ConnectionString, "StoredProcedure_Insert", True, True)
        Catch ex As Exception
        End Try
    End Sub

Open in new window

spen_langAuthor Commented:

Would this also allow the user to make changes/UPDATEs to the new record (e.g. if they made a typo when inserting). The reason I was going down the dataset route was because I could then create UPDATE and DELETE commands also.

If this method will do the trick, please could you send me more information about the class that you have mentioned?

Thanks, Greg
Ess KayEntrapenuerCommented:
sure, just make another function for update, one for delete, one for select, with a stored procedure for each
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.