如何让查询的数据gridview中显示
protectedvoidButton1_Click(objectsender,EventArgse){stringstrConnection=Configuration...
protected void Button1_Click(object sender, EventArgs e)
{
string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
if (RadioButton1.Checked)
{
string sql = " select * from six where accountingnum = '" + TextBox1.Text + "' or name = '" + TextBox2.Text + "' or idcard = '" + TextBox3.Text + "'";
/*OleDbCommand com = new OleDbCommand(sql );
OleDbDataReader ord = com.ExecuteReader();
DataSet ds = new DataSet();
ord.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
//*/
OleDbCommand com = new OleDbCommand(sql,objConnection );
OleDbDataReader ord = com.ExecuteReader();
GridView1.DataSource = ord;
GridView1.DataBind();
} 展开
{
string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
if (RadioButton1.Checked)
{
string sql = " select * from six where accountingnum = '" + TextBox1.Text + "' or name = '" + TextBox2.Text + "' or idcard = '" + TextBox3.Text + "'";
/*OleDbCommand com = new OleDbCommand(sql );
OleDbDataReader ord = com.ExecuteReader();
DataSet ds = new DataSet();
ord.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
//*/
OleDbCommand com = new OleDbCommand(sql,objConnection );
OleDbDataReader ord = com.ExecuteReader();
GridView1.DataSource = ord;
GridView1.DataBind();
} 展开
3个回答
2015-07-17 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464984
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
public void GridViewBind()//gridvie数据绑定方法
{
//实例化SqlConnection对象
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = "server=.;uid=sa;pwd=;database=SearchDB";
//定义SQL语句
string SqlStr = "select * from Discussion";
//实例化SqlDataAdapter对象
SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon);
//实例化数据集DataSet
DataSet ds = new DataSet();
da.Fill(ds, "Discussion");
//绑定DataList控件
GridView1.DataSource = ds;//设置数据源,用于填充控件中的项的值列表
GridView1.DataBind();//将控件及其所有子控件绑定到指定的数据源
}
获取你查询的值!使用select 字段 from 表查询表中的数据,然后重新填充 GridView。
{
//实例化SqlConnection对象
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = "server=.;uid=sa;pwd=;database=SearchDB";
//定义SQL语句
string SqlStr = "select * from Discussion";
//实例化SqlDataAdapter对象
SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon);
//实例化数据集DataSet
DataSet ds = new DataSet();
da.Fill(ds, "Discussion");
//绑定DataList控件
GridView1.DataSource = ds;//设置数据源,用于填充控件中的项的值列表
GridView1.DataBind();//将控件及其所有子控件绑定到指定的数据源
}
获取你查询的值!使用select 字段 from 表查询表中的数据,然后重新填充 GridView。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询