我无法在文本框中获取记录 [英] i can not get record in textbox

查看:85
本文介绍了我无法在文本框中获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用以下代码...
在输入名称的同时,在文本框中没有在另一个文本框中获得记录...

请帮助我

By using below code...
In textbox while I input Name, I did not get record in another textbox ...

Please help me

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)

推荐答案


在gridview中,将数据源分配为您的数据集,并将数据成员分配为表名.然后在按钮单击事件中调用适配器填充方法...

例如...
抱歉,代码在c#中.我希望不难理解并更改为VB.Net

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

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)
 }



您需要让ds引用数据集的实时实例.假定为winform,它将填充gridview.如果是webform,则分配数据源和datameber,然后调用gridview1.DataBind()方法(在gidview属性中,autogenerate列必须在webform中设置为true).

如果您想逐行浏览,请循环执行..

例子..



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


什么是"inc"?

尝试更改sql以对您的sql进行硬编码-并独立测试该sql以确保获得结果.

然后在调试中运行,并确保获得结果.

是不填充文本框,还是引发异常?
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?


这篇关于我无法在文本框中获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆