如题,我打算通过一个文本框和两个下拉列表框中的数据对gridview的数据进行筛选
可是我的代码运行后却没反应,谁能看看哪有错了? protected void btncha_Click(object sender, EventArgs e)
{
string source = "server=(local);integrated security=SSPI;database=cxsys";
SqlConnection conn=new SqlConnection(source);
SqlCommand cmd = conn.CreateCommand();
SqlCommand cmd1=new SqlCommand();
SqlCommand cmd2=new SqlCommand();
string name, baobiao, jishui;
name = this.txtleibiename.Text.ToString();
baobiao = this.combbaobiao.Text.ToString();
jishui = this.combjishui.Text.ToString();
cmd.CommandText = "SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where xmlbname='" +
name + "')";
cmd1.CommandText="SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where orbaobiao='" +
baobiao + "')";
cmd2.CommandText="SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where orjishui='" +
jishui + "')";
try
{
conn.Open();
if(this.txtleibiename!=null)
{
SqlDataReader reader = cmd.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
this.SqlDataSource1.DataBind();
reader.Close();
}
else if(this.combbaobiao.Text!=null)
{
SqlDataReader reader = cmd1.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
reader.Close();
}
else if(this.combjishui.Text!=null)
{
SqlDataReader reader = cmd2.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
reader.Close();
}
}
catch (Exception ex)
{
Response.Write("<script>window.alert('错误!"+ex.Message.ToString()+"')</script>");
}
finally
{
conn.Close();
} }谢谢了
可是我的代码运行后却没反应,谁能看看哪有错了? protected void btncha_Click(object sender, EventArgs e)
{
string source = "server=(local);integrated security=SSPI;database=cxsys";
SqlConnection conn=new SqlConnection(source);
SqlCommand cmd = conn.CreateCommand();
SqlCommand cmd1=new SqlCommand();
SqlCommand cmd2=new SqlCommand();
string name, baobiao, jishui;
name = this.txtleibiename.Text.ToString();
baobiao = this.combbaobiao.Text.ToString();
jishui = this.combjishui.Text.ToString();
cmd.CommandText = "SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where xmlbname='" +
name + "')";
cmd1.CommandText="SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where orbaobiao='" +
baobiao + "')";
cmd2.CommandText="SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where orjishui='" +
jishui + "')";
try
{
conn.Open();
if(this.txtleibiename!=null)
{
SqlDataReader reader = cmd.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
this.SqlDataSource1.DataBind();
reader.Close();
}
else if(this.combbaobiao.Text!=null)
{
SqlDataReader reader = cmd1.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
reader.Close();
}
else if(this.combjishui.Text!=null)
{
SqlDataReader reader = cmd2.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
reader.Close();
}
}
catch (Exception ex)
{
Response.Write("<script>window.alert('错误!"+ex.Message.ToString()+"')</script>");
}
finally
{
conn.Close();
} }谢谢了
解决方案 »
- 关于.net序列化的疑问
- 分页数据和总记录数能读一次数据库就同时得到吗?
- .net 生成xml 关于 xsi:type
- 怎么发送信息,页面进行提示呀
- AjaxPro怎么引用
- 难以开口的问题
- js 修改DataList中的url绑定列的url值,第一个可以修改,后面的就修改不了 在线等
- asp.net 中javascript获取flv播放器播放完毕的状态
- 如何利用asp.net 在web中播放mepg4的视频
- QQ第三方登陆 登陆成功后回调地址页面自动关闭的问题
- webconfig中的一个小问题,高手进 在线等。。。。
- Apache HTTP Server2.2 使用Response.WriteFile 输出图片报错
SqlCommand cmd2=new SqlCommand();
if(this.txtleibiename!=null)
以上三行有问题
而不是
combbaobiao.Text==null
{
string name, baobiao, jishui;
name = this.txtleibiename.Text.ToString();
baobiao = this.combbaobiao.Text.ToString();
jishui = this.combjishui.Text.ToString();
string source = "server=(local);integrated security=SSPI;database=cxsys";
string nm = "SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where xmlbname='" +
name + "')";
string bb = "SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where orbaobiao='" +
baobiao + "')";
string js = "SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx where orjishui='" +
jishui + "')";
SqlConnection conn=new SqlConnection(source);
SqlCommand cmd = new SqlCommand(nm,conn);
SqlCommand cmd1=new SqlCommand(bb,conn);
SqlCommand cmd2=new SqlCommand(js,conn); try
{
conn.Open();
if(this.txtleibiename.Text!=null)
{
SqlDataReader reader = cmd.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
this.SqlDataSource1.DataBind();
reader.Close();
}
else if(this.combbaobiao.Text!="")
{
SqlDataReader reader = cmd1.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
reader.Close();
}
else if(this.combjishui.Text!="")
{
SqlDataReader reader = cmd2.ExecuteReader();
this.GridView1.DataSource = reader;
this.GridView1.DataBind();
reader.Close();
}
}
catch (Exception ex)
{
Response.Write("<script>window.alert('错误!"+ex.Message.ToString()+"')</script>");
}
finally
{
conn.Close();
} }
SqlConnection con=new SqlConnection("server=....");
SqlDataAdapter adapter=new SqlDataAdapter("select * from...",con);
DataSet ds=new DataSet();
adapter.Fill(ds,"表名");
GridView1.DataSource=ds;
GridView1.DataBind();
不知道这个方法是否可行,现在问题是报错
“GridView1”上同时定义了 DataSource 和 DataSourceID。请移除一个定义。
部分代码如下:string name, baobiao, jishui;
name = this.txtleibiename.Text.ToString();
baobiao = this.combbaobiao.SelectedValue.ToString();
jishui = this.combjishui.SelectedValue.ToString();
try
{
if(this.txtleibiename.Text!=null)
{
string txtconn = "server=(local);integrated security=SSPI;database=cxsys";
SqlConnection conn = new SqlConnection(txtconn);
string txtcommand = "SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(txtcommand, conn);
da.Fill(ds, "cwxzflx");
GridView1.DataSource = ds;
GridView1.DataMember = "cwxzflx";
DataView dw = new DataView(ds.Tables["cwxzflx"]);
dw.RowFilter = "xmlbname='" + name + "'";
GridView1.DataSource = dw; }
else if(this.combbaobiao.Text!="")
{
string txtconn = "server=(local);integrated security=SSPI;database=cxsys";
SqlConnection conn = new SqlConnection(txtconn);
string txtcommand = "SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(txtcommand, conn);
da.Fill(ds, "cwxzflx");
GridView1.DataSource = ds;
GridView1.DataMember = "cwxzflx";
DataView dw = new DataView(ds.Tables["cwxzflx"]);
dw.RowFilter = "orbaobiao='" + baobiao + "'";
GridView1.DataSource = dw;
}
else if(this.combjishui.Text!="")
{
string txtconn = "server=(local);integrated security=SSPI;database=cxsys";
SqlConnection conn = new SqlConnection(txtconn);
string txtcommand = "SELECT xmlbname, orbaobiao, orjishui FROM cwxzflx";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(txtcommand, conn);
da.Fill(ds, "cwxzflx");
GridView1.DataSource = ds;
GridView1.DataMember = "cwxzflx";
DataView dw = new DataView(ds.Tables["cwxzflx"]);
dw.RowFilter = "orjishui='" + jishui + "'";
GridView1.DataSource = dw;
}
}
catch (Exception ex)
{
Response.Write("<script>window.alert('错误!"+ex.Message.ToString()+"')</script>");
}