尝试导管问题显示信息 [英] problem in try cath & show information

查看:124
本文介绍了尝试导管问题显示信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我在asp.net2005中编写了以下代码,以通过sql.2005从数据库获取信息.

hello
I wrote bellow codes in asp.net2005 for take information from DB via sql.2005

try
        {
            GridView2.Visible = true;
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=NezamPezeshki;Integrated Security=True");
            SqlDataSource1.SelectCommand = "SELECT * FROM [ViewSParvandeh] WHERE (([Dfamily] LIKE '%' + @Dfamily + '%') OR ([Dname] LIKE '%' + @Dname + '%') OR ([DNum] LIKE '%' + @DNum + '%'))";
            SqlDataSource1.SelectParameters.Clear();
            SqlDataSource1.SelectParameters.Add("DNum", TextBox1.Text);
            SqlDataSource1.SelectParameters.Add("Dname", TextBox2.Text);
            SqlDataSource1.SelectParameters.Add("Dfamily", TextBox3.Text);
            SqlDataSource1.SelectParameters.Add("MelliCode", TextBox4.Text);
            SqlDataSource1.SelectParameters.Add("Expr1", TextBox5.Text);
            SqlDataSource1.SelectParameters.Add("MajorName", TextBox6.Text);
            SqlDataSource1.SelectParameters.Add("IdNum", TextBox7.Text);
            SqlDataSource1.SelectParameters.Add("CityParvaneh", DropDownList2.Text);

            GridView2.DataBind();

          

        }
        catch
        {
            Label10.Text = "no register these information";

        }



但是我有2个问题:
1-为什么要尝试导管式的工作?
2-我应该填写三个文本框以向我显示信息,但是像这样,有时我想将其中的一些留空,但是这种方式对我来说什么都不显示!!!!
请帮助我
感谢



BUT I HAVE 2 PROBLEMs:
1- why try cath dosent work?
2- I should fill three of textbox for show info to me BUT idont like this,sometimes I want blank some of them,but in this way doesnt show to me anything!!!!!

please help me
thanks

推荐答案

尝试一下:
Try this:
catch(exception ex)
      {
          Label10.Text = ex.message + "Your message here";

      }


在将数据绑定到GridView之前,您应该执行sql命令,然后使用dataadapter填充数据集,然后将数据集的datatable设置为GridView.
Before binding the data to GridView, you should execute the sqlcommand and then use dataadapter to fill the dataset and then set the dataset''s datatable as the datasource for the GridView.


根据解决方案1尝试捕获块写入代码
in try catch block write code as per solution 1
catch(exception ex)
      {
          Label10.Text = ex.message + "Your message here";

      }



我认为当您绑定gridview时,您没有执行命令,因此没有数据来.并且您尚未定义gridview的数据源.



i think when you bind gridview you are not executing command so no data coming. and you have not define the datasource of gridview.


这篇关于尝试导管问题显示信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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