Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI all!!!

i am trying to retrieve some values from database and showing it in a gridview. When i am running the application it is giving me error on da.fill(ds) that
Cannot call methods on text.
I searched it online but there is no information about this error.

here is the code for .aspx

XML
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Panel ID="Panel1" runat="server"  ScrollBars="Both" Width="100%">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            CellPadding="4" ForeColor="#333333" GridLines="None" Width="717px"
            Height="95px">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
            <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%#Eval("Name")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Applied For">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%#Eval("JobTitle")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="MobileNo">
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%#Eval("MobileNo")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Email-Id">
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%#Eval("Email")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Qualification">
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%#Eval("ProfessionalQualification")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Experience -Year">
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server" Text='<%#Eval("TotlaExpYear") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Experience - Month">
                <ItemTemplate>
                    <asp:Label ID="Label7" runat="server" Text='<%#Eval("TotalExpMonth") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Current Location">
                <ItemTemplate>
                    <asp:Label ID="Label8" runat="server" Text='<%#Eval("CurrentLocation") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    </asp:Panel>
</asp:Content>





here is the code for .aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Employer_EmployerViewResume : System.Web.UI.Page
{
    SqlConnection con;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Employer"] == null )
        {
            Response.Redirect("EmployerLogin.aspx");
        }
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString);
        con.Close();
        
        databind();
    }

    private void databind()
    {
        con.Open();
       

        SqlDataAdapter da =  new  SqlDataAdapter("Select a.Name , a.JobTitle , a.UserId , a.JobID ,a.Status,a.AppliedDate,b.MobileNo, b.Email,b.ProfessionalQualification,b.TotalExpYear.b.TotalExpMonth,b.CurrentLocation from Applied a join JobSeeker b on a.UserId= b.UserId order by a.Status DESC ,a.AppliedDate ASC",  con) ;
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
}
Posted

1 solution

I believe your UserId column has a 'TEXT' data type. Joins cannot be performed on text, ntext & image fields.

Use a varchar(xx) or nvarchar(xx) for the UserId field as the datatype & your join should work
 
Share this answer
 
Comments
ujjwal uniyal 4-Dec-11 12:40pm    
yes sir the problem was that i had a text datatype but when i changed the datatype to int it says " cannot call method on int. " LOL . any solution for that ??? :)

anyways 5 star from me for the correct answer.
strogg 4-Dec-11 13:02pm    
You changed UserId to int? Are you have set both Applied.UserId and JobSeeker.UserId to int? Also try by putting [] brackets around column names
ujjwal uniyal 5-Dec-11 1:15am    
ok sir, i will try this. Thanks for the valuable advise.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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