Search code examples
c#datatablewebmethod

{"Message":"Cannot find column [AbDate].","StackTrace":" at System.Data.NameNode.Bind(DataTable table, List`1 list) Error


I am using webmethod to load data . I want to check a particular data is existing or not in this data. So, I bind it to a datatable . But I found an error in the network as

{"Message":"Cannot find column [AbDate].","StackTrace":" at System.Data.NameNode.Bind(DataTable table, List1 list).

But the column AbDate is existing. I am sure because I check the values using break point . AbDate

[WebMethod]
    public static IList GetEvents(string Start, string End, double OS_Idno, double Gs_Id, string AccYear, double Sid)
    {
 DataSet ds = new DataSet();
 DataTable dt1 = new DataTable();
    SqlDataAdapter sda = new SqlDataAdapter("My query", con);
    sda.Fill(dt1);
    ds.Tables.Add(dt1);
    for (int i = 0; i < dt1.Rows.Count; i++)
    {
        DateTime AttDate = Convert.ToDateTime(dt1.Rows[i]["OSA_Dateofattendance"]);
        DataRow[] Date1 = ds.Tables[0].Select("AbDate='" + AttDate + "' and Os_idno='" + OS_Idno + "'");
        if (Date1.Count() == 0)
        {
        }
        else
        {
        }
    }
}

But when I change the code as

DataRow[] Date1 = ds.Tables[0].Select("Os_idno='" + OS_Idno + "'");

It works for me . And the main issue is the problem is not in my local only in the server. I have a full calendar to show this results. In the console I found a error as

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Please help I don't have an idea what to do


Solution

  • I think you must change your query such as:

    SELECT AbDate AS AD …
    

    and use AD instead of AbDate in your filtering like this:

    DataRow[] Date1 = ds.Tables[0].Select("AD='" + AttDate + "' and Os_idno='" + OS_Idno + "'");