navigate through sql records problem

drpcken

Member
Joined
Jun 15, 2004
Messages
12
Programming Experience
1-3
Have a problem and can't put my finger on how to get it to work.

I'm making a webform, in the webform there are textbox controls. I'll use 3 for this example.

txtFirstName
txtMI
txtLastName

I also have a SQL table, (connections already created and working) where i have 3 columns: FirstName, MI, LastName. They also have a primary key called RecId which is just an autonumber.

I have 2 buttons: btnPrev and btnNext. See where I'm going with this? I want to click btnNext and have it put the values of the three columns in sql into the corrosponding 3 textboxes, and when I hit btnNext again, go to the next record, and so forth. When I hit btnPrev i want it to move to the previous record in the database.

I'm thinking I need to create a dataset holding this information, but getting it from the dataset to the txtboxes is stumping me.

PLEASE HELP!!! Thank you guys so much!!
 
First, add databindings to the text boxes:

VB.NET:
txtMI.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DataSetName, "MI"))

To do the previous and next buttons use this code (I also threw in Last and First record code):
VB.NET:
'Next:
Me.BindingContext(DataSetName, "TableName").Position = _
  (Me.BindingContext(DataSetName, "TableName").Position + 1)
'Previous:
Me.BindingContext(DataSetName, "TableName").Position = _
  (Me.BindingContext(DataSetName, "TableName").Position - 1)
'Last:
Me.BindingContext(DataSetName, "TableName").Position = _
  (Me.objdsDataForm.Tables("TableName").Rows.Count - 1)
'First:
Me.BindingContext(objdsDataForm, "TableName").Position = 0
 
txtMI.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DataSetName, "MI"))


Visual Studio doesn't like that line, especially the system.windows.forms.binding, says its not a member.

Remember I'm using Vb.NET and kinda noobish, I tried importing it, but theres no system.windows namespace
 
The Binding class is a member of the System.Windows.Forms namespace. If you created a WinForm app, you should already have this reference. The 'DataBindings' property for txtMI is also a member of that namespace (as are textboxes, forms, ...).

Since you are using Visual Studio, you could use the Data Form Wizard which will do all this work for you. Then you can view the code to see how it's done. This is how I learned dataBinding.

To start the Data Form Wizard: from an existing project click 'File' -> 'Add New Item'; in the dialog select 'Data Form Wizard' and follow the instructions.
 
Everything you said makes perfect sense, but its telling me that my

me.BindingContext is not a member of ProjectName.WebFormName

I even tried adding this to my form:

Imports System.Windows.Forms

to import the namespace, but it tells me my namespace isn't valid.

Is something seriously messed up here?
 
I didn't read your very first post very well; you're creating a webForm, I was thinking WinForm. Sorry.

The standard way to display tables in WebForms is by using a datagrid or repeater to create a table of information.

If you want to view single records, you could load the dataset into a session variable and keep track of the current record number also with a session variable; increment or decrement the record number with the button event handlers and display that record number.

I'm not too strong with webForms so I'm not sure of the best method. :)
 
Back
Top