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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question on scope and datasets

Status
Not open for further replies.

modfather

MIS
Feb 15, 2000
75
US
Hoping someone can help me out:

I have a fairly simple windows application that uses an Access database. I'd like to bind textboxes to my dataset, but am unsure where I'm going wrong... The problem is, upon "GotFocus" of a certain textbox, I want to open a dataset and keep it open (disconnected, of course) for editing. When hitting a "Save" button, I want to apply any changes to the dataset and update the database. The problem I have is: most of the documentation I've found focuses around datagrids, and I'm not wanting to display this data in a grid. It's a typical windows form. So the question is: How can I open a dataset in my GotFocus event, but then have that same dataset available "in scope" at the "click" event for my Save button? I'm quite the newbie, so I apologize for the simple question, but I'm really stuck! I have a feeling I'm not using the best method to create my DataSet, but I'm a bit lost... Here's a small piece of my source code:

Private Sub txtScore1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtScore1.GotFocus
Dim ds As DataSet = ExecuteDataSet("SELECT ScoreA1 FROM results where cardnum = 239 and compnum = '114'")
End Sub

Main.vb (module)
Function ExecuteDataSet(ByVal sSQLString As String) As DataSet
Dim da As New OleDbDataAdapter(sSQLString, strConn)
Dim ds As New DataSet
da.Fill(ds)
Return ds
End Function

I guess another question would be: If I create the DataSet in an event, it's not available anywhere else, right? If not, then how do I create it so that it's available upon hitting the "Save" button? ...confused!... :)

Thanks!
Steve
 
I realize this doesn't answer your specific questions, but...

I would use the Data Form Wizard, when asked "How do you want to display your data" select "Single records in individual controls".
After making this selection, you have the ability to add controls for editing and navigation, the wizard does all the work for you!

If you don't like the results, at least you have a great starting point.

One way to start the Data Form Wizard: Right click the project in the Solution Explorer; Add > Add New Item...; in the dialog box under Templates, choose Data Form Wizard, Type a name and click Open.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top