Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
I wrote bellow codes in asp.net2005 for take information from DB via sql.2005

C#
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";

        }


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
Posted
Updated 22-Jun-12 1:55am
v2
Comments
Sandeep Mewara 22-Jun-12 8:02am    
What do you mean 'try-catch' doesn't work?
Prosan 22-Jun-12 9:17am    
where are you exceuting command.

Try this:
C#
catch(exception ex)
      {
          Label10.Text = ex.message + "Your message here";

      }
 
Share this answer
 
v2
Comments
veusk 22-Jun-12 8:24am    
thanks
but unfortunately the parts of catch no work,again
Rajeev Jayaram 22-Jun-12 8:50am    
May be the try block didn't meet with an exception as you didn't execute the sqlcommand. See my answer.
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.
 
Share this answer
 
in try catch block write code as per solution 1
C#
catch(exception ex)
      {
          Label10.Text = ex.message + "Your message here";

      }


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900