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.
 
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.
 
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?
 
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?
 
I just checked. It is (1), return_value is (0) it seems. Thank you anyway for persisting with this! Your help is much appreciated.
 
Back
Top