Problem With DataGrid (Select)

Ujjwalvb

New member
Joined
Feb 24, 2006
Messages
2
Programming Experience
Beginner
Hi
I am new to this group.

The problem is to display the data in DataGrid
In order to retrieve all the values from the DataBase the following code Runs Without any error.


con1 = New SqlConnection("Persist Security Info=False;User ID=sa;Initial Catalog=Test;Data Source=SERVER\SOFTWARE")
ada1 = New SqlDataAdapter("select * from t2", con1)
MsgBox("Adapter ok:")
dss = New DataSet()
ada1.Fill(dss, "t2")
dg.DataSource = dss.Tables("t2").DefaultView
*******************************************
BUT IF
*******************************************
What we have to do in order to retrieve the value
based upon the value specified in the textbox or Combo Box.
The structure of the Table is some thing like this
it has 3 columns Name age and M.no

Only name field is displayed in the combobox or Name value is specified in the text field

I want to retrive the whole row based upon that Value
I already used these code

*******************************************************
dim gh as string
gh = "select * from t2 where name=' " & Trim(ComboBox1.Text) & " ' "
Dim ada2 = New SqlDataAdapter(gh, con1)
Dim dsss = New DataSet()
ada2.Fill(dsss, "t2")
dg.DataSource = dss.Tables("t2").DefaultView
******************************************************
But it will again show all the Records



Ujjwal G
 
I also want to clear my concepts regarding your problem,so I'm trying to work it out. However any kind of help from other members is appreciated.
 
Create DataView from DataSet, filter DataView with RowFilter property & assign to DataGrid as –

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load
Ds1.Clear()
DAMast.Fill(Ds1, "Master")
ComboBox1.DataSource = Ds1.Tables("Master")
ComboBox1.DisplayMember = "Name"
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim dv As DataView
dv = Ds1.Tables("Master").DefaultView
dv.RowFilter = "Name = '" & ComboBox1.Text & "'"
DataGrid1.DataSource = dv
End Sub

Could do the same thing with DevForce!! (At the cost of repeating myself)
 
Back
Top