Click here to Skip to main content
15,903,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
By using below code...
In textbox while I input Name, I did not get record in another textbox ...

Please help me

VB
Dim str1 = TBSER.Text
        Dim sql1 As String = "select * from EmpInfo where EmpName='" + str1 + "'"
        adp = New SqlDataAdapter(sql1, cn)
        adp.Fill(ds)
        TBID.Text = ds.Tables("EmpInfo").Rows(inc).Item(0)
        TBNAME.Text = ds.Tables("EmpInfo").Rows(inc).Item(1)
        TBAD1.Text = ds.Tables("EmpInfo").Rows(inc).Item(2)
        TBAD2.Text = ds.Tables("EmpInfo").Rows(inc).Item(3)
        CBCITY.Text = ds.Tables("EmpInfo").Rows(inc).Item(4)
        TBTEL1.Text = ds.Tables("EmpInfo").Rows(inc).Item(5)
        TBTEL2.Text = ds.Tables("EmpInfo").Rows(inc).Item(6)
        TBMOB.Text = ds.Tables("EmpInfo").Rows(inc).Item(7)
        CBFAC.Text = ds.Tables("EmpInfo").Rows(inc).Item(8)
Posted
Updated 23-Feb-11 0:41am
v4
Comments
thatraja 22-Feb-11 21:10pm    
what's the problem, any error message? include that in your question.
[no name] 22-Feb-11 21:50pm    
Is this field case senstive?
somil030 22-Feb-11 22:09pm    
yes i can not get result,no error...
Dalek Dave 23-Feb-11 6:42am    
Edited for Grammar and Readability.

Hi
In the gridview assign data source as your dataset and datamember as the table name. Then call the adapter fill method in a button click event...

For example...
Sorry the code is in c#. I hope it is not hard to understand and change to VB.Net

C#
private void button2_Click(object sender, EventArgs e)
 {
     dataGridView1.DataSource = ds;
     dataGridView1.DataMember = "EmpInfo";
     Dim str1 = TBSER.Text
     Dim sql1 As String = "select * from EmpInfo where EmpName='" + str1 + "'"
     adp = New SqlDataAdapter(sql1, cn)
     adp.Fill(ds)
 }


You need to have the ds should refer to an live instance of the dataset. It will fill the gridview as it is assumed a winform. If it is webform assign the datasource and datameber and then call the gridview1.DataBind() method (In the gidview properties autogenerate column has to set true in webform).

In case you want to go row by row then do it in a loop..

example..
DataTable dt=ds.Tables["EmpInfo"];
foreach(DataRow row in dt.rows){
    TBID.Text=row.item[0];
}

But here for each loop the text box get over written. How you want to handle it. Better grid view
 
Share this answer
 
v3
Comments
somil030 22-Feb-11 22:52pm    
but this article can not work ,gridview can't select given Name
somil030 22-Feb-11 22:54pm    
this code does not work pls provide another way to get selection record in gridview
Albin Abel 25-Feb-11 23:55pm    
ok, you want to select employee name right? after that what should happen? Give an example what you are trying to acheive
What's 'inc' ?

Try changing the sql to hard-code your sql - and test that sql independently to make sure you get a result.

Then run in debug and makes sure you get a result.

Are the text boxes not being populated, or is an exception being thrown?
 
Share this answer
 
Comments
Dalek Dave 23-Feb-11 6:42am    
Well Spotted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900