Problem with SELECT Statement

G

Guest

I have a select statement that isn’t functioning properly:



private void Page_Load(object sender, System.EventArgs e)

{

myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);

dsClub=new DataSet();



string
strClubconn=ConfigurationSettings.AppSettings["ConnectionString"];

ClubConn=new SqlConnection(strClubconn);

ClubConn.Open();

string strClubcmdRead="SELECT EVNR_tbl.* FROM EVNR_tbl
WHERE EVNR_tbl._Date BETWEEN '" + myClubNow1.Date.ToString("dd/MM/yyyy") + "'
AND '" + myClubNow1.Date.AddDays(3).ToString("dd/MM/yyyy") + "'";

clubAdapt=new SqlDataAdapter(strClubcmdRead, ClubConn);

clubAdapt.Fill(dsClub,"EVNR_tbl");



Repeater1.DataSource=dsClub;

Repeater1.DataBind();

ClubConn.Close();

}

When I debug it shows the proper dates but at run-time when the site comes
up it doesn’t return any event information even though I know the table
EVNR_tbl has information. The Structure of the data table is as follows:



Column Name datatype example



EVNRID int 1

_Date DateTime 04/03/2005

Duration int 1

Broadcast bit 0

EventTitle char(255) Vivid's last night

Description Text Last night etc etc

Details Text Etc etc etc





I don’t know why it is not returning any data on the web site when I know
there are records. It was working yesterday. Please help.
 
G

Guest

This should be switched over to parameterized queries or stored procedures if
this is going to be real production code. To get it working currently,
change the first line to

myClubNow1 = DateTime.Now; // this is more readable than what you have

and change your select statement to use the one true date format
("yyyyMMdd")

01/02/03 can mean different things depending on your regional settings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top