Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process automation

Status
Not open for further replies.

wlaflamme

Technical User
Aug 1, 2003
22
US
Hello,
I am a very very basic programmer and I have been struggling with a problem witing data to a database. I am building a machine that is communicating through a serial connection to a process meter. I am retrieving this data, plotting on a chart and hopefully recording it to a db that I created with VB2005 Express. The problem I am having is that I create a new row with all my data as described in a MSDN help topic but nothing seems to be saved to the DB file. Here is the code... Do I need to update the dataset somehow?

Public Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

Dim newMeasurementRow As InsideShoeDBDataSet.MeasurementRow
newMeasurementRow = InsideShoeDBDataSet1.Measurement.NewMeasurementRow()

newMeasurementRow._Date = date1
newMeasurementRow.Time = time1
newMeasurementRow.Style = style
newMeasurementRow.Model = model
newMeasurementRow.Gender = gender
newMeasurementRow.Size = length
newMeasurementRow.Width = width1
newMeasurementRow.Last = last
newMeasurementRow.Measurement1 = actual
newMeasurementRow.Measurement2 = actual
newMeasurementRow.Measurement3 = actual
newMeasurementRow.Measurement4 = actual
newMeasurementRow.Measurement5 = actual
newMeasurementRow.Measurement6 = actual
newMeasurementRow.Measurement7 = actual
newMeasurementRow.Measurement8 = actual
newMeasurementRow.Measurement9 = actual
newMeasurementRow.Measurement10 = actual

InsideShoeDBDataSet1.Measurement.Rows.Add(newMeasurementRow)
End Sub

I appreciate any help....
Billy
 

Hey Billy,

How are you sending the updated rows to the database? The procedure you posted is adding the line to your dataset, but it isn't sending it back to the database.

 
Well this is probably my issue. The MSDN help did not say anything about this so I am unaware of how to do this? Do you have any suggestions on how to 's for this topic or could you walk me through it?
 
I don't know how you built your form or what happens before you get to the point of running this procedure, so this is a bit generic.

If you dragged the dataset onto your form from the Data Sources box all the objects below will have been set up automatically for you.

Basically you're going to need an SQL Connection and a data adapter, which you may already have. Make sure your adapter has an Insert Command. If it doesn't you can use a CommandBuilder to create one. Just create a new instance with your data adapter as the argument. The GetInsertCommand method of the command builder will give you the update command. I generally don't like using the command builder, I prefer writing stored procedures for database access, but when you're getting started its a big help.

Once you get the insert command you call the data adapter's Update method to write your changes back to the database.

I know thats a pretty crappy description, so here are a few links that may help clear things up.

This one is the MSDN page on updating a data source with a data adapter:


This is a link to Microsoft's free videos on database-based forms. Sometimes watching a walkthrough helps thing click.

Here's a google search I had saved in my favorites with some good resources:

One more thing you may want to look into, if you haven't already, is the connection string section of the app.config. Using this takes the connection string out of the compiled code, so makes it much easier to switch between test and production database servers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top