Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:30:48+00:00 2026-06-13T22:30:48+00:00

I am populating the GridView with following code on basis of Numeric data put

  • 0

I am populating the GridView with following code on basis of Numeric data put in the textbox and clicking the button.
But it is giving the following error.
Error converting data type varchar to float.
As my database column ‘matri_perct’ has datatype ‘float’.

protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL Connection String"].ConnectionString);con.Open();
        com = new SqlCommand("SELECT * FROM stdtable WHERE matri_perct >  @Percent", con);
        com.Parameters.AddWithValue("Percent", float.Parse(txtPercent.Text));
        com.ExecuteNonQuery();
            SqlDataAdapter dataadapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            dataadapter.Fill(ds, "Data");
            GridView1.DataSource = ds;
            GridView1.DataMember = "Data";
            con.Close();
        }
        catch (System.Exception err)
        {
            Label1.Text = err.Message.ToString();
        }
    }

My GridView .aspx code is declared as

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="univ_regno" DataSourceID="" EnableModelValidation="True">
    <Columns>
        <asp:BoundField DataField="school" HeaderText="School" 
            SortExpression="school" />
        <asp:BoundField DataField="univ_regno" HeaderText="Univ R.No." ReadOnly="True" 
            SortExpression="univ_regno" />
        <asp:BoundField DataField="colge_rollno" HeaderText="Coll. R.No." 
            SortExpression="colge_rollno" />
        <asp:BoundField DataField="branch" HeaderText="Branch" 
            SortExpression="branch" />
        <asp:BoundField DataField="sem" HeaderText="Sem" SortExpression="sem" />
        <asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
        <asp:BoundField DataField="f_name" HeaderText="F.Name" 
            SortExpression="f_name" />
        <asp:BoundField DataField="date_birth" HeaderText="DOB" 
            SortExpression="date_birth" />

        <asp:BoundField DataField="mob" HeaderText="Mobile" 
            SortExpression="mob" />
        <asp:BoundField DataField="email" HeaderText="E-mail" SortExpression="email" />
        <asp:BoundField DataField="matri_perct" HeaderText="Matric %" 
            SortExpression="matri_perct" />
        <asp:BoundField DataField="intermed_perct" HeaderText="Intermediate %" 
            SortExpression="intermed_perct" />
        <asp:BoundField DataField="grad_perct" HeaderText="UG %" 
            SortExpression="grad_perct" />
        <asp:BoundField DataField="post_grad_perct" HeaderText="PG %" 
            SortExpression="post_grad_perct" />
        <asp:BoundField DataField="other_perct" HeaderText="Other %" 
            SortExpression="other_perct" />
        <asp:BoundField DataField="no_backlogs" HeaderText="Backlogs" 
            SortExpression="no_backlogs" />
        <asp:BoundField DataField="Password" HeaderText="Password" 
            SortExpression="Password" />
    </Columns>
</asp:GridView>
  <asp:SqlDataSource ID="studentprofile" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SQL Connection String %>" 

        SelectCommand="SELECT DISTINCT [school], [univ_regno], [colge_rollno], [branch], [sem], [name], [f_name], [date_birth], [cores_add], [mob], [email], [matri_perct], [intermed_perct], [grad_perct], [post_grad_perct], [other_perct], [no_backlogs], [Password] FROM [stdtable] ORDER BY [branch], [univ_regno]">
    </asp:SqlDataSource>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:30:49+00:00Added an answer on June 13, 2026 at 10:30 pm

    I have solved my question with the help of @Bob Kaufman & @rene
    The complete solution of my question is following:

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
    
            con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL Connection String"].ConnectionString);
            con.Open();
            com = new SqlCommand("SELECT * FROM stdtable WHERE matri_perct >  @Percent", con);
            com.Parameters.AddWithValue("@Percent", float.Parse(txtPercent.Text));
            SqlDataReader reader = com.ExecuteReader();  // execute SELECT statement, store result in data reader
            GridView1.DataSource = reader;
            GridView1.DataBind();
            con.Close();
             }
        catch (System.Exception err)
        {
            Label1.Text = err.Message.ToString();
        }
    }
    

    And then i have changed the AllowPaging=false

    It works 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Friends, I'm populating a GridView in my asp.net application using following code. GridView grdExport
I have created a gridview for populating data, and some user control (TextBox) to
I have the following code for populating a dropdownlist in my gridviews footer. if
Here is how I'm populating my GridView control. I'm doing this from the code-behind,
ASP.NET: Which strategy is better for populating a gridview? filling a Data Table and
I have the following scenario. I have two methods of populating a GridView with
I have a question about an ImageAdapter for populating the GridView . Following is
Basically I am populating a gridview from a sql table. But the problem is
I have added a button column to a gridview. I am populating the gridview
I have a gridview that I am populating with data for the folks in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.