Empty Dataset Connected to Database for Insert

Hi,

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
spen_langAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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()
      
        Try
           
            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

0
spen_langAuthor Commented:
Hi,

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
0
Ess KayEntrapenuerCommented:
sure, just make another function for update, one for delete, one for select, with a stored procedure for each
0
CodeCruiserCommented:
But if you want to go the dataset route then your approach of running a select command to return 0 rows would work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.