Query string of "DateTime" format using ASP.NET

bnstaylor

New Member
Hi,

I am having problems passing a query string over to another URL page with the URL page expecting that one of the fields being passed to be of type "DateTime" when the field is actually only a standard PROGRESS "Date" field. SQL does not allow you to declare a field as "Date" only. I need this field as it forms part of a key element to access the table used in the other URL page.

When I decalre the field as:


<asp:QueryStringParameter Name="?" QueryStringField="ItemProdnDate"
Type="DateTime" />


The page does not load.

If I remove this QueryStringParameter and just leave the other parameters which are just strings, the page loads. But as I stated above I need the date to isolate particular records I want.


Regards, Barry.
 

bnstaylor

New Member
Hi,

Was in the middle of replying to you yesterday when I accidentally hit the ALT key and ProgressTalk locked-up and I had to crash it ….. :(

Anyway, sorry to be so late in my response but since I have created this web portal for the business they have bombarded me with requests for new work.

I believe I understand what you are saying is? :
  1. In the code behind file of the sending page convert the DATE/TIME field to a STRING,
  2. Send the string field across to the next page,
  3. Have the next page convert the string into a PROGRESS DATE field by using the DATE command against the string on the SELECT command
We have not proceeded down this path for a couple of reasons:
  1. We have another index on the table that gives us the same unique record with only a three key element instead of the nine key elements,
  2. I am trying to minimize, if not totally eliminate, the need to execute any code behind files.
I appreciate your help and would like to know your thoughts on the above scenario.

Regards, Barry.
 

bnstaylor

New Member
Hi Tom,

right. In the code behind on the first page I had to put the following:

protected void LinkButton1_Click(object sender, EventArgs e)
{
string BusPartner = DropDownList1.Text + "!" + TextBox3.Text;
string shipto = TextBox4.Text;
if (shipto == "")
{
BusPartner = BusPartner + TextBox4.Text;
}
else
{
BusPartner = BusPartner +
"!" + TextBox4.Text;
}
 
CultureInfo culture = new CultureInfo("en-US");
string date1 = TextBox1.Text.Substring(3, 2) + "/" + TextBox1.Text.Substring(0, 2) + "/" + TextBox1.Text.Substring(6, 4);
DateTime DateFrom = Convert.ToDateTime(date1, culture).Date;
 
string date2 = TextBox2.Text.Substring(3, 2) + "/" + TextBox2.Text.Substring(0, 2) + "/" + TextBox2.Text.Substring(6, 4);
DateTime DateTo = Convert.ToDateTime(date2, culture).Date;
 
Response.Redirect(
"SelectedMultipleByDate.aspx?" + "Buyer=" + BusPartner + "&DateFrom=" + DateFrom + "&DateTo=" + DateTo);
}

and in the code behind of the next page I had to put:


public
void Page_Load(object sender, EventArgs e)
{
Label1.Text =
Convert.ToString(Request.QueryString["Buyer"]);
DateTime fromdate = Convert.ToDateTime(Request.QueryString["DateFrom"]).Date;
Label3.Text = (fromdate.ToString(
"dd/MM/yyyy"));
DateTime todate = Convert.ToDateTime(Request.QueryString["DateTO"]).Date;
Label4.Text = (todate.ToString(
"dd/MM/yyyy"));
}


This all worked find and gave what I wanted.

Thx, Barry.

 
Top