使用where子句显示列表视图中的数据,其中textbox值与数据库中的值相同 [英] display data in list view with where clause where textbox value same as in database

查看:46
本文介绍了使用where子句显示列表视图中的数据,其中textbox值与数据库中的值相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在列表视图中显示数据,其中where子句where random_no = textbox2.text。

这是m代码



private void BindListView( )

{

// SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ApplicationServices]。ToString());



string constr = ConfigurationManager.ConnectionStrings [ApplicationServices]。ConnectionString;

using(SqlConnection con = new SqlConnection(constr))

{

使用(SqlCommand cmd = new SqlCommand())

{

cmd.CommandText =select * from descroption where [random_no] ='+ TetxBox2.Text +';

cmd.Connection = con;

使用(SqlDataAdapter sda = new SqlDataAdapter(cmd))

{

DataTable dt = new D. ataTable();

sda.Fill(dt);

ListView3.DataSource = dt;

ListView3.DataBind();

}

}

}

}





想显示文本框值相同的数据

display data in list view with where clause where random_no = textbox2.text.
this is m code

private void BindListView()
{
//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());

string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select * from descroption where [random_no] = '"+ TetxBox2.Text+"' ";
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
ListView3.DataSource = dt;
ListView3.DataBind();
}
}
}
}


want to show data where textbox value same

推荐答案

HI Aarti,



您可以创建一个过滤器数据表来选择过滤后的数据并将其显示到列表视图中。



HI Aarti,

You can create a filter data-table to select the filtered data on it and show that to the list view.

Datatable tempFilterData = _dt.Select("random_no = " + textbox.text).CopyToDataTable();





然后使用过滤的数据表显示在列表视图上。



Then use the filtered datatable to be shown on the listview.


这篇关于使用where子句显示列表视图中的数据,其中textbox值与数据库中的值相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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