Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to compare the data entered in a textbox to the data I have in DataTable but I am getting this error: Cannot find column [Date].
T-Sql code:
SQL
ALTER PROC [dbo].[getCreditCard]

AS
BEGIN
   IF NOT EXISTS(SELECT CardNumber,NameOnCard,ExpiresEnd As MyDate FROM  [dbo].[CardBank] )
       begin
         PRINT N'Request failed!'
         return 0
       end
       else
       begin
          select * from [dbo].[CardBank]
          PRINT N'Request succeeded'
          return 1
        end
END

and c# code:

C#
DataTable dt = _CreditCardInfo.GetCreditCard().Tables[0];
       _CreditCardInfo.CardNumber = TextBoxCardNumber.Text.Trim();
       string dropDowlistYear = DropDownListYears.SelectedValue;
       string dropDowlistMonth = DropDownListMonth.SelectedValue;
       DataRow[] drCardNumber = dt.Select("CardNumber='" + TextBoxCardNumber.Text.ToString().Trim() + "'");
       DataRow[] drNameOnCard = dt.Select("NameOnCard='" + TextBoxNameOnCard.Text.ToString() + "'");
       DataRow[] drValidFrom = dt.Select("MyDate='" + dropDowlistYear + "/" + dropDowlistMonth + "'");
       //DataRow[] ExpiresEnd = dt.Select("ExpYear='" + dropDowlistMonth1 + "'");
       if (drCardNumber.Length > 0 && drNameOnCard.Length > 0 && drValidFrom.Length > 0)
       {
           Response.Redirect("Default.aspx");
       }
       else
       {
           LabelMessage.Text = "The Card name or Card Number are invalid.";
           LabelMessage.ForeColor = Color.Red;
           return;
       }


and this the code inside my class:
SQL
public DataSet GetCreditCard()
    {
        return SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), "[getCreditCard]");
    }


As u can see I want to get it from Datatable.
Can someone help!
Posted
Updated 28-Mar-13 1:48am
v2
Comments
ZurdoDev 28-Mar-13 8:00am    
"Cannot find column [Date]." You have a column named MyDate, not Date.

1 solution

Change the else part of your stored procedure from

SELECT * FROM [dbo].[CardBank]

To

SELECT CardNumber,NameOnCard,ExpiresEnd As MyDate FROM [dbo].[CardBank]
 
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