Data Refresh Problem

paula

New member
Joined
Nov 29, 2004
Messages
4
Programming Experience
Beginner
Hi all,

I am brand new to vb.net and am trying to write my first app. So far I have a form which has some textboxes at the top. The data for these boxes is retrieved from running a stored procedure using a sql dataadapter. Below that I have a datagrid. The data for thsi is retrieved also by using a stored proc. A parameter is passed in (containing data from one of the above text boxes) to link the data inthe text boxes to the datagrid info. This all works fine. I have a combo box from which the user can select a different record. When the user changes the value in the combo box (by dropping the list down and selecting), the data in the text boxes changes appropriately (I didn't code this, it just happens!). however the data in the datagrid needs to be refreshed to disply the correct row. How do I do this? I've tried adding code to the SelectValueChanged event of the combo box, to say clear the dataset, pass the parm again, re-run the stored proc and set the datagrid to the datsource, but it does nothing.

Any ideas? I would be very grateful.

Thank,

Paula.
 

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
hi paula welcome.
try to post your code.. for us to see.

that would be helpful.
 

paula

New member
Joined
Nov 29, 2004
Messages
4
Programming Experience
Beginner
Here's the code....

Thanks for replying. I now get the following error message:

An unhandled exception of type 'System.NullReferenceException' occurred in CONTRISGP.exe
Additional information: Object reference not set to an instance of an object.

Here's the code, I've put the offending line in italics:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

SqlConnection1.Open()

'load dataset to fill textboxes

SqlDataAdapter1.Fill(DataSet12)

'set parameter and load dataset to fill practice datagrid

SqlDataAdapter2.SelectCommand.Parameters(1).Value = txtPracCode.Text

SqlDataAdapter2.Fill(DataSet12.practicesub)

'set the datasource of the datagrid

PracDataGrid.DataSource = DataSet12.practicesub

'set parameter and load dataset to fill gp datagrid

SqlDataAdapter3.SelectCommand.Parameters(1).Value = txtPracCode.Text

SqlDataAdapter3.Fill(DataSet12.praclinkedGPs)

'set the datasource of the datagrid

GPDataGrid.DataSource = DataSet12.praclinkedGPs

'SqlConnection1.Close()

'sqlconnection1.dispose()

'sqlconnection1 = nothing

End Sub

Private Sub cboPracName_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPracName.SelectedValueChanged

'on change, re-load all data for the selected practice

DataSet12.practicesub.Clear()

SqlDataAdapter2.SelectCommand.Parameters(1).Value = txtPracCode.Text

SqlDataAdapter2.Fill(DataSet12.practicesub)

PracDataGrid.DataSource = DataSet12.practicesub

End Sub

End
Class

Thanks for your help.
 

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
Try this line

open up the section marked 'Windows Form Designer generated code'

you need to find 'SqlSelectCommand2

mine looks like this:
'SqlSelectCommand2
'
Me.SqlSelectCommand2.CommandText = "SELECT [Assy Part ID], [Detail Number], [Detail Part ID], [Qty per Assy], Report FROM Detail WHERE ([Assy Part ID] = @asspartid)"

Then modify your line to look like this
SqlSelectCommand1.Parameters("@asspartid").Value = textbox1.txt

You need to make sure to match up data types, [Assy Part ID] needs to be string

When setting up the SQLDataAdapter in the Query wizard there is a column 'criteria'
On the row of the field you want to select enter '=@asspartid'
and the correct where clause will be added.
You can change this value by right clicking on the SQLDataAdapter and selecting configure data adapter and following the steps.


does this help?
 

paula

New member
Joined
Nov 29, 2004
Messages
4
Programming Experience
Beginner
Stored Proc

I'm using stored procedures to select the data. Therefore I have an input parameter in my stored proc. That is what is happening when I do this:

SqlDataAdapter2.SelectCommand.Parameters(1).Value = txtPracCode.Text

I think that is the same as what you just mentioned in an ad hoc sql statement.

I think the problem is somewhere in the sqldataadapter2 - it doesn't seem to recognise what it is.

Any more ideas anyone?
 

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
Try checking the (1) , could it be (0)?
my reference book shows a parameter of (0).
 

paula

New member
Joined
Nov 29, 2004
Messages
4
Programming Experience
Beginner
I just checked. It is (1), return_value is (0) it seems. Thank you anyway for persisting with this! Your help is much appreciated.
 
Top Bottom