Showing posts with label stuck. Show all posts
Showing posts with label stuck. Show all posts

Tuesday, March 13, 2012

stuck and confused

Ok, here is my scenario, I have an asp web app that i'm converting to .net.
The app reads files and loads the data into SQL db, now, in my file it has
numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads the
files into the db and I run query analyzer I see the numbers as they are in
the file, but when I upload the same file in my .net version of the app, I
see the numbers like this in query anaylzer: 125.25636363, 3363.3320001,
69.0000001. The columns are defined as floats in the table, and I changed the
types in the code from float to double and even tried decimal, but no luck,
any suggestions on how to get the numbers to show correctly from my .NET app
when I run query anaylzer?how are you going from the text file to code to the database?

are you using xxx.Parse() (like float.Parse()) on a string or something...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/

"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
> Ok, here is my scenario, I have an asp web app that i'm converting to
> .net.
> The app reads files and loads the data into SQL db, now, in my file it has
> numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads the
> files into the db and I run query analyzer I see the numbers as they are
> in
> the file, but when I upload the same file in my .net version of the app, I
> see the numbers like this in query anaylzer: 125.25636363, 3363.3320001,
> 69.0000001. The columns are defined as floats in the table, and I changed
> the
> types in the code from float to double and even tried decimal, but no
> luck,
> any suggestions on how to get the numbers to show correctly from my .NET
> app
> when I run query anaylzer?
the code isn't doing float.parse(), i picked the app up from a former
developer and trying to fix the mess left behind. He's reading the text
files, creating a datatable, then inserting that into the table. in the
datatable, he has something like this:
aColumn = new DataColumn(SALESAMOUNT, System.Type.GetType("System.Single"));

"Karl Seguin [MVP]" wrote:

> how are you going from the text file to code to the database?
> are you using xxx.Parse() (like float.Parse()) on a string or something...
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
> > Ok, here is my scenario, I have an asp web app that i'm converting to
> > .net.
> > The app reads files and loads the data into SQL db, now, in my file it has
> > numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads the
> > files into the db and I run query analyzer I see the numbers as they are
> > in
> > the file, but when I upload the same file in my .net version of the app, I
> > see the numbers like this in query anaylzer: 125.25636363, 3363.3320001,
> > 69.0000001. The columns are defined as floats in the table, and I changed
> > the
> > types in the code from float to double and even tried decimal, but no
> > luck,
> > any suggestions on how to get the numbers to show correctly from my .NET
> > app
> > when I run query anaylzer?
>
is he then doing somethng like

DataRow row = databable.NewRow();
row["SalesAmount"] = someValue;
or
row[12] = someValue;

?

if so, what type is someValue? a string?

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/

"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
> the code isn't doing float.parse(), i picked the app up from a former
> developer and trying to fix the mess left behind. He's reading the text
> files, creating a datatable, then inserting that into the table. in the
> datatable, he has something like this:
> aColumn = new DataColumn(SALESAMOUNT,
> System.Type.GetType("System.Single"));
>
> "Karl Seguin [MVP]" wrote:
>> how are you going from the text file to code to the database?
>>
>> are you using xxx.Parse() (like float.Parse()) on a string or
>> something...
>>
>> Karl
>>
>> --
>> http://www.openmymind.net/
>> http://www.fuelindustries.com/
>>
>>
>> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
>> > Ok, here is my scenario, I have an asp web app that i'm converting to
>> > .net.
>> > The app reads files and loads the data into SQL db, now, in my file it
>> > has
>> > numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads
>> > the
>> > files into the db and I run query analyzer I see the numbers as they
>> > are
>> > in
>> > the file, but when I upload the same file in my .net version of the
>> > app, I
>> > see the numbers like this in query anaylzer: 125.25636363,
>> > 3363.3320001,
>> > 69.0000001. The columns are defined as floats in the table, and I
>> > changed
>> > the
>> > types in the code from float to double and even tried decimal, but no
>> > luck,
>> > any suggestions on how to get the numbers to show correctly from my
>> > .NET
>> > app
>> > when I run query anaylzer?
>>>
>>
>
like this:

DataRow row = databable.NewRow();
row["SalesAmount"] = arr[1].toString();

"Karl Seguin [MVP]" wrote:

> is he then doing somethng like
> DataRow row = databable.NewRow();
> row["SalesAmount"] = someValue;
> or
> row[12] = someValue;
> ?
> if so, what type is someValue? a string?
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
> > the code isn't doing float.parse(), i picked the app up from a former
> > developer and trying to fix the mess left behind. He's reading the text
> > files, creating a datatable, then inserting that into the table. in the
> > datatable, he has something like this:
> > aColumn = new DataColumn(SALESAMOUNT,
> > System.Type.GetType("System.Single"));
> > "Karl Seguin [MVP]" wrote:
> >> how are you going from the text file to code to the database?
> >>
> >> are you using xxx.Parse() (like float.Parse()) on a string or
> >> something...
> >>
> >> Karl
> >>
> >> --
> >> http://www.openmymind.net/
> >> http://www.fuelindustries.com/
> >>
> >>
> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> >> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
> >> > Ok, here is my scenario, I have an asp web app that i'm converting to
> >> > .net.
> >> > The app reads files and loads the data into SQL db, now, in my file it
> >> > has
> >> > numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads
> >> > the
> >> > files into the db and I run query analyzer I see the numbers as they
> >> > are
> >> > in
> >> > the file, but when I upload the same file in my .net version of the
> >> > app, I
> >> > see the numbers like this in query anaylzer: 125.25636363,
> >> > 3363.3320001,
> >> > 69.0000001. The columns are defined as floats in the table, and I
> >> > changed
> >> > the
> >> > types in the code from float to double and even tried decimal, but no
> >> > luck,
> >> > any suggestions on how to get the numbers to show correctly from my
> >> > .NET
> >> > app
> >> > when I run query anaylzer?
> >> >>
> >>
> >>
>
well...so far everything looks ok...

can you put a breakpoint and see what format arr[1] is in. My guess is that
it's happening when the value is first loaded from the text file (perhaps
into arr[1]). Can you provide more chunks of code?

Karl

--
http://www.openmymind.net/

"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
> like this:
> DataRow row = databable.NewRow();
> row["SalesAmount"] = arr[1].toString();
>
> "Karl Seguin [MVP]" wrote:
>> is he then doing somethng like
>>
>> DataRow row = databable.NewRow();
>> row["SalesAmount"] = someValue;
>> or
>> row[12] = someValue;
>>
>> ?
>>
>> if so, what type is someValue? a string?
>>
>> Karl
>> --
>> http://www.openmymind.net/
>> http://www.fuelindustries.com/
>>
>>
>> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>> news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
>> > the code isn't doing float.parse(), i picked the app up from a former
>> > developer and trying to fix the mess left behind. He's reading the text
>> > files, creating a datatable, then inserting that into the table. in the
>> > datatable, he has something like this:
>> > aColumn = new DataColumn(SALESAMOUNT,
>> > System.Type.GetType("System.Single"));
>>>>> > "Karl Seguin [MVP]" wrote:
>>> >> how are you going from the text file to code to the database?
>> >>
>> >> are you using xxx.Parse() (like float.Parse()) on a string or
>> >> something...
>> >>
>> >> Karl
>> >>
>> >> --
>> >> http://www.openmymind.net/
>> >> http://www.fuelindustries.com/
>> >>
>> >>
>> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>> >> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
>> >> > Ok, here is my scenario, I have an asp web app that i'm converting
>> >> > to
>> >> > .net.
>> >> > The app reads files and loads the data into SQL db, now, in my file
>> >> > it
>> >> > has
>> >> > numbers like, 125.25, 3363.33, 69.00, and when the asp version
>> >> > uploads
>> >> > the
>> >> > files into the db and I run query analyzer I see the numbers as they
>> >> > are
>> >> > in
>> >> > the file, but when I upload the same file in my .net version of the
>> >> > app, I
>> >> > see the numbers like this in query anaylzer: 125.25636363,
>> >> > 3363.3320001,
>> >> > 69.0000001. The columns are defined as floats in the table, and I
>> >> > changed
>> >> > the
>> >> > types in the code from float to double and even tried decimal, but
>> >> > no
>> >> > luck,
>> >> > any suggestions on how to get the numbers to show correctly from my
>> >> > .NET
>> >> > app
>> >> > when I run query anaylzer?
>> >>> >>
>> >>
>> >>
>>
>>
>
I did that, and all the way through I can see the number being uploaded as
125.25, so could it be a SQL thing transforming the numbers or something I'm
missing?

"Karl Seguin [MVP]" wrote:

> well...so far everything looks ok...
> can you put a breakpoint and see what format arr[1] is in. My guess is that
> it's happening when the value is first loaded from the text file (perhaps
> into arr[1]). Can you provide more chunks of code?
> Karl
> --
> http://www.openmymind.net/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
> > like this:
> > DataRow row = databable.NewRow();
> > row["SalesAmount"] = arr[1].toString();
> > "Karl Seguin [MVP]" wrote:
> >> is he then doing somethng like
> >>
> >> DataRow row = databable.NewRow();
> >> row["SalesAmount"] = someValue;
> >> or
> >> row[12] = someValue;
> >>
> >> ?
> >>
> >> if so, what type is someValue? a string?
> >>
> >> Karl
> >> --
> >> http://www.openmymind.net/
> >> http://www.fuelindustries.com/
> >>
> >>
> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> >> news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
> >> > the code isn't doing float.parse(), i picked the app up from a former
> >> > developer and trying to fix the mess left behind. He's reading the text
> >> > files, creating a datatable, then inserting that into the table. in the
> >> > datatable, he has something like this:
> >> > aColumn = new DataColumn(SALESAMOUNT,
> >> > System.Type.GetType("System.Single"));
> >> >> >> >> > "Karl Seguin [MVP]" wrote:
> >> >> >> how are you going from the text file to code to the database?
> >> >>
> >> >> are you using xxx.Parse() (like float.Parse()) on a string or
> >> >> something...
> >> >>
> >> >> Karl
> >> >>
> >> >> --
> >> >> http://www.openmymind.net/
> >> >> http://www.fuelindustries.com/
> >> >>
> >> >>
> >> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> >> >> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
> >> >> > Ok, here is my scenario, I have an asp web app that i'm converting
> >> >> > to
> >> >> > .net.
> >> >> > The app reads files and loads the data into SQL db, now, in my file
> >> >> > it
> >> >> > has
> >> >> > numbers like, 125.25, 3363.33, 69.00, and when the asp version
> >> >> > uploads
> >> >> > the
> >> >> > files into the db and I run query analyzer I see the numbers as they
> >> >> > are
> >> >> > in
> >> >> > the file, but when I upload the same file in my .net version of the
> >> >> > app, I
> >> >> > see the numbers like this in query anaylzer: 125.25636363,
> >> >> > 3363.3320001,
> >> >> > 69.0000001. The columns are defined as floats in the table, and I
> >> >> > changed
> >> >> > the
> >> >> > types in the code from float to double and even tried decimal, but
> >> >> > no
> >> >> > luck,
> >> >> > any suggestions on how to get the numbers to show correctly from my
> >> >> > .NET
> >> >> > app
> >> >> > when I run query anaylzer?
> >> >> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
If the SQL column is a float, you might wanna try changing it to a decimal.
You'll also want to make sure your SqlCommand has a decimal type. Something
like:

command.CommandType = CommandType.Text;
command.CommandText = "INSERT INTO SomeTable (SalesAmount) VALUES
(@.SalesAmount)";
command.Parameters.Add("@.SalesAmount", SqlDbType.Decimal);
command.Parameters[0].SourceColumn = "SalesAmount";

Karl
--
http://www.openmymind.net/

"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:5EF97DBC-4C69-4B07-A484-9A95230A8208@.microsoft.com...
>I did that, and all the way through I can see the number being uploaded as
> 125.25, so could it be a SQL thing transforming the numbers or something
> I'm
> missing?
>
> "Karl Seguin [MVP]" wrote:
>> well...so far everything looks ok...
>>
>> can you put a breakpoint and see what format arr[1] is in. My guess is
>> that
>> it's happening when the value is first loaded from the text file (perhaps
>> into arr[1]). Can you provide more chunks of code?
>>
>> Karl
>>
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>> news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
>> > like this:
>>> > DataRow row = databable.NewRow();
>> > row["SalesAmount"] = arr[1].toString();
>>>>> > "Karl Seguin [MVP]" wrote:
>>> >> is he then doing somethng like
>> >>
>> >> DataRow row = databable.NewRow();
>> >> row["SalesAmount"] = someValue;
>> >> or
>> >> row[12] = someValue;
>> >>
>> >> ?
>> >>
>> >> if so, what type is someValue? a string?
>> >>
>> >> Karl
>> >> --
>> >> http://www.openmymind.net/
>> >> http://www.fuelindustries.com/
>> >>
>> >>
>> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>> >> news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
>> >> > the code isn't doing float.parse(), i picked the app up from a
>> >> > former
>> >> > developer and trying to fix the mess left behind. He's reading the
>> >> > text
>> >> > files, creating a datatable, then inserting that into the table. in
>> >> > the
>> >> > datatable, he has something like this:
>> >> > aColumn = new DataColumn(SALESAMOUNT,
>> >> > System.Type.GetType("System.Single"));
>> >>> >>> >>> >> > "Karl Seguin [MVP]" wrote:
>> >>> >> >> how are you going from the text file to code to the database?
>> >> >>
>> >> >> are you using xxx.Parse() (like float.Parse()) on a string or
>> >> >> something...
>> >> >>
>> >> >> Karl
>> >> >>
>> >> >> --
>> >> >> http://www.openmymind.net/
>> >> >> http://www.fuelindustries.com/
>> >> >>
>> >> >>
>> >> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>> >> >> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
>> >> >> > Ok, here is my scenario, I have an asp web app that i'm
>> >> >> > converting
>> >> >> > to
>> >> >> > .net.
>> >> >> > The app reads files and loads the data into SQL db, now, in my
>> >> >> > file
>> >> >> > it
>> >> >> > has
>> >> >> > numbers like, 125.25, 3363.33, 69.00, and when the asp version
>> >> >> > uploads
>> >> >> > the
>> >> >> > files into the db and I run query analyzer I see the numbers as
>> >> >> > they
>> >> >> > are
>> >> >> > in
>> >> >> > the file, but when I upload the same file in my .net version of
>> >> >> > the
>> >> >> > app, I
>> >> >> > see the numbers like this in query anaylzer: 125.25636363,
>> >> >> > 3363.3320001,
>> >> >> > 69.0000001. The columns are defined as floats in the table, and I
>> >> >> > changed
>> >> >> > the
>> >> >> > types in the code from float to double and even tried decimal,
>> >> >> > but
>> >> >> > no
>> >> >> > luck,
>> >> >> > any suggestions on how to get the numbers to show correctly from
>> >> >> > my
>> >> >> > .NET
>> >> >> > app
>> >> >> > when I run query anaylzer?
>> >> >>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>
I can't change the column in the db due to it "replication" to other tables,
etc. I did make it a decimal in the SQLCommand, but still no go. I can see
it in the table correctly via enterprise manager, but when i do a query via
Query analzer is where I'm seeing the incorrect number format.

"Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u013J8xPGHA.3016@.tk2msftngp13.phx.gbl...
> If the SQL column is a float, you might wanna try changing it to a
> decimal. You'll also want to make sure your SqlCommand has a decimal type.
> Something like:
> command.CommandType = CommandType.Text;
> command.CommandText = "INSERT INTO SomeTable (SalesAmount) VALUES
> (@.SalesAmount)";
> command.Parameters.Add("@.SalesAmount", SqlDbType.Decimal);
> command.Parameters[0].SourceColumn = "SalesAmount";
>
> Karl
> --
> http://www.openmymind.net/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:5EF97DBC-4C69-4B07-A484-9A95230A8208@.microsoft.com...
>>I did that, and all the way through I can see the number being uploaded as
>> 125.25, so could it be a SQL thing transforming the numbers or something
>> I'm
>> missing?
>>
>>
>> "Karl Seguin [MVP]" wrote:
>>
>>> well...so far everything looks ok...
>>>
>>> can you put a breakpoint and see what format arr[1] is in. My guess is
>>> that
>>> it's happening when the value is first loaded from the text file
>>> (perhaps
>>> into arr[1]). Can you provide more chunks of code?
>>>
>>> Karl
>>>
>>> --
>>> http://www.openmymind.net/
>>>
>>>
>>>
>>> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>>> news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
>>> > like this:
>>>>> > DataRow row = databable.NewRow();
>>> > row["SalesAmount"] = arr[1].toString();
>>>>>>>>> > "Karl Seguin [MVP]" wrote:
>>>>> >> is he then doing somethng like
>>> >>
>>> >> DataRow row = databable.NewRow();
>>> >> row["SalesAmount"] = someValue;
>>> >> or
>>> >> row[12] = someValue;
>>> >>
>>> >> ?
>>> >>
>>> >> if so, what type is someValue? a string?
>>> >>
>>> >> Karl
>>> >> --
>>> >> http://www.openmymind.net/
>>> >> http://www.fuelindustries.com/
>>> >>
>>> >>
>>> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>>> >> news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
>>> >> > the code isn't doing float.parse(), i picked the app up from a
>>> >> > former
>>> >> > developer and trying to fix the mess left behind. He's reading the
>>> >> > text
>>> >> > files, creating a datatable, then inserting that into the table. in
>>> >> > the
>>> >> > datatable, he has something like this:
>>> >> > aColumn = new DataColumn(SALESAMOUNT,
>>> >> > System.Type.GetType("System.Single"));
>>> >>>> >>>> >>>> >> > "Karl Seguin [MVP]" wrote:
>>> >>>> >> >> how are you going from the text file to code to the database?
>>> >> >>
>>> >> >> are you using xxx.Parse() (like float.Parse()) on a string or
>>> >> >> something...
>>> >> >>
>>> >> >> Karl
>>> >> >>
>>> >> >> --
>>> >> >> http://www.openmymind.net/
>>> >> >> http://www.fuelindustries.com/
>>> >> >>
>>> >> >>
>>> >> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>>> >> >> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
>>> >> >> > Ok, here is my scenario, I have an asp web app that i'm
>>> >> >> > converting
>>> >> >> > to
>>> >> >> > .net.
>>> >> >> > The app reads files and loads the data into SQL db, now, in my
>>> >> >> > file
>>> >> >> > it
>>> >> >> > has
>>> >> >> > numbers like, 125.25, 3363.33, 69.00, and when the asp version
>>> >> >> > uploads
>>> >> >> > the
>>> >> >> > files into the db and I run query analyzer I see the numbers as
>>> >> >> > they
>>> >> >> > are
>>> >> >> > in
>>> >> >> > the file, but when I upload the same file in my .net version of
>>> >> >> > the
>>> >> >> > app, I
>>> >> >> > see the numbers like this in query anaylzer: 125.25636363,
>>> >> >> > 3363.3320001,
>>> >> >> > 69.0000001. The columns are defined as floats in the table, and
>>> >> >> > I
>>> >> >> > changed
>>> >> >> > the
>>> >> >> > types in the code from float to double and even tried decimal,
>>> >> >> > but
>>> >> >> > no
>>> >> >> > luck,
>>> >> >> > any suggestions on how to get the numbers to show correctly from
>>> >> >> > my
>>> >> >> > .NET
>>> >> >> > app
>>> >> >> > when I run query anaylzer?
>>> >> >>>> >> >>
>>> >> >>
>>> >> >>
>>> >>
>>> >>
>>> >>
>>>
>>>
>>>
I don't think there's a good solution in that case. It would seem that the
person who designed the database might not have understood what Floats are.
Floating points are an approximate representation of your number - not all
values can't be represented. Decimals are used for exact numbers.

You might want to check out:
http://msdn.microsoft.com/library/d...con_03_6mht.asp

Karl
--
http://www.openmymind.net/

"CsharpGuy" <me@.me.com> wrote in message
news:e7jOI55PGHA.2108@.TK2MSFTNGP10.phx.gbl...
>I can't change the column in the db due to it "replication" to other
>tables, etc. I did make it a decimal in the SQLCommand, but still no go. I
>can see it in the table correctly via enterprise manager, but when i do a
>query via Query analzer is where I'm seeing the incorrect number format.
>
> "Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
> net> wrote in message news:u013J8xPGHA.3016@.tk2msftngp13.phx.gbl...
>> If the SQL column is a float, you might wanna try changing it to a
>> decimal. You'll also want to make sure your SqlCommand has a decimal
>> type. Something like:
>>
>> command.CommandType = CommandType.Text;
>> command.CommandText = "INSERT INTO SomeTable (SalesAmount) VALUES
>> (@.SalesAmount)";
>> command.Parameters.Add("@.SalesAmount", SqlDbType.Decimal);
>> command.Parameters[0].SourceColumn = "SalesAmount";
>>
>>
>> Karl
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>> news:5EF97DBC-4C69-4B07-A484-9A95230A8208@.microsoft.com...
>>>I did that, and all the way through I can see the number being uploaded
>>>as
>>> 125.25, so could it be a SQL thing transforming the numbers or something
>>> I'm
>>> missing?
>>>
>>>
>>> "Karl Seguin [MVP]" wrote:
>>>
>>>> well...so far everything looks ok...
>>>>
>>>> can you put a breakpoint and see what format arr[1] is in. My guess is
>>>> that
>>>> it's happening when the value is first loaded from the text file
>>>> (perhaps
>>>> into arr[1]). Can you provide more chunks of code?
>>>>
>>>> Karl
>>>>
>>>> --
>>>> http://www.openmymind.net/
>>>>
>>>>
>>>>
>>>> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>>>> news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
>>>> > like this:
>>>>>>> > DataRow row = databable.NewRow();
>>>> > row["SalesAmount"] = arr[1].toString();
>>>>>>>>>>>>> > "Karl Seguin [MVP]" wrote:
>>>>>>> >> is he then doing somethng like
>>>> >>
>>>> >> DataRow row = databable.NewRow();
>>>> >> row["SalesAmount"] = someValue;
>>>> >> or
>>>> >> row[12] = someValue;
>>>> >>
>>>> >> ?
>>>> >>
>>>> >> if so, what type is someValue? a string?
>>>> >>
>>>> >> Karl
>>>> >> --
>>>> >> http://www.openmymind.net/
>>>> >> http://www.fuelindustries.com/
>>>> >>
>>>> >>
>>>> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
>>>> >> news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
>>>> >> > the code isn't doing float.parse(), i picked the app up from a
>>>> >> > former
>>>> >> > developer and trying to fix the mess left behind. He's reading the
>>>> >> > text
>>>> >> > files, creating a datatable, then inserting that into the table.
>>>> >> > in the
>>>> >> > datatable, he has something like this:
>>>> >> > aColumn = new DataColumn(SALESAMOUNT,
>>>> >> > System.Type.GetType("System.Single"));
>>>> >>>>> >>>>> >>>>> >> > "Karl Seguin [MVP]" wrote:
>>>> >>>>> >> >> how are you going from the text file to code to the database?
>>>> >> >>
>>>> >> >> are you using xxx.Parse() (like float.Parse()) on a string or
>>>> >> >> something...
>>>> >> >>
>>>> >> >> Karl
>>>> >> >>
>>>> >> >> --
>>>> >> >> http://www.openmymind.net/
>>>> >> >> http://www.fuelindustries.com/
>>>> >> >>
>>>> >> >>
>>>> >> >> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in
>>>> >> >> message
>>>> >> >> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
>>>> >> >> > Ok, here is my scenario, I have an asp web app that i'm
>>>> >> >> > converting
>>>> >> >> > to
>>>> >> >> > .net.
>>>> >> >> > The app reads files and loads the data into SQL db, now, in my
>>>> >> >> > file
>>>> >> >> > it
>>>> >> >> > has
>>>> >> >> > numbers like, 125.25, 3363.33, 69.00, and when the asp version
>>>> >> >> > uploads
>>>> >> >> > the
>>>> >> >> > files into the db and I run query analyzer I see the numbers as
>>>> >> >> > they
>>>> >> >> > are
>>>> >> >> > in
>>>> >> >> > the file, but when I upload the same file in my .net version of
>>>> >> >> > the
>>>> >> >> > app, I
>>>> >> >> > see the numbers like this in query anaylzer: 125.25636363,
>>>> >> >> > 3363.3320001,
>>>> >> >> > 69.0000001. The columns are defined as floats in the table, and
>>>> >> >> > I
>>>> >> >> > changed
>>>> >> >> > the
>>>> >> >> > types in the code from float to double and even tried decimal,
>>>> >> >> > but
>>>> >> >> > no
>>>> >> >> > luck,
>>>> >> >> > any suggestions on how to get the numbers to show correctly
>>>> >> >> > from my
>>>> >> >> > .NET
>>>> >> >> > app
>>>> >> >> > when I run query anaylzer?
>>>> >> >>>>> >> >>
>>>> >> >>
>>>> >> >>
>>>> >>
>>>> >>
>>>> >>
>>>>
>>>>
>>>>
>>
>>

Stuck again

Hi Guys

Here is my problem

I have a sql database with a field voucherRate(int4) that contains a figure that will be used to create a discount.

Here is my code so far


'Declare the discount string
dim strDiscount as double
'declare the total string
dim strTotal as double = 10
Sub Page_Load
'set up connection to db
Dim conNorthwind As SqlConnection
Dim dsEmployees As DataSet
dsEmployees = New Dataset

' Retrieve records from database
conNorthwind = New SqlConnection( "server=(local);uid=sa;pwd=*****;database=dbSQL" )
Dim daEmployees As SQLDataAdapter
daEmployees = New SqlDataAdapter( "Select voucherRate from vouchers", conNorthwind )
daEmployees.Fill( dsEmployees, "voucherRate" )

conNorthwind.Close()
strDiscount = daEmployees( "VoucherRate" )
End Sub

OK what I need to add but am really struggling with is this;
strDiscount = "DataSet Voucher Rate" / 100 * strTotal

What would be the correct syntax for creating this stringFirst of all...
I find your variable names very different...
I am not sure why you have "str" before all your variables...
Check out MSDN site for naming convention...

Anyhow...
here's the code to access your voucherRate field...


conNorthwind.close()

strDiscount = CType(dsEmployees.Tables(0).Rows(0).Item("voucherRate"),Integer)/100 * strTotal

But please note that your dataset might have more than one records and hence you have to loop through the dataset to calculate discount for all the records...

Stuck

im building a ecommerce site (still)
any way i need to work out the shipping fee depending on the combined weight off the products.
each product has a column in the database called weight and at moment is an integer??

heres the sql statment

ALTER PROCEDURE GetTotalWeight
(@dotnet.itags.org.CartID varchar(50))
AS

DECLARE @dotnet.itags.org.Amount int

SELECT @dotnet.itags.org.Amount = SUM(Product.[Weight]*ShoppingCart.Quantity)
FROM ShoppingCart
INNER JOIN Product
ON ShoppingCart.ProductID = Product.ProductID
WHERE ShoppingCart.CartID = @dotnet.itags.org.CartID

IF @dotnet.itags.org.Amount IS NULL
SELECT 0
ELSE
SELECT @dotnet.itags.org.Amount
RETURN

heres the procedure!
Public Function GetTotalWeight() As Decimal
' Create the connection object
Dim connection As New SqlConnection(connectionString)

' Create and initialize the command object
Dim command As SqlCommand = New SqlCommand("GetTotalWeight", connection)
command.CommandType = CommandType.StoredProcedure

' Add an input parameter and supply a value for it
command.Parameters.Add("@dotnet.itags.org.CartID", SqlDbType.VarChar, 50)
command.Parameters("@dotnet.itags.org.CartID").Value = shoppingCartId

' Save the total amount to a variable
Dim amount As Decimal
connection.Open()
amount = command.ExecuteScalar()

' Close the connection
connection.Close()

' Return the amount
Return amount

If amount <= 1000 Then
amount = 3.46
ElseIf amount > 1000 < 1500 Then
amount = 4.45
ElseIf amount > 1500 <= 2000 Then
amount = 4.78
ElseIf amount > 2000 <= 4000 Then
amount = 7.2
ElseIf amount > 4000 <= 6000 Then
amount = 7.86
ElseIf amount > 6000 <= 8000 Then
amount = 8.96
ElseIf amount > 8000 <= 10000 Then
amount = 9.62
ElseIf amount > 10000 Then
amount = 11.21
End If

End Function

heres it setting it to the label
ShippingCostLabel.Text = String.Format("{0:c}", cart.GetTotalWeight())

obviousley this is wrong as the returned vale is always the combined weight so it obviousley bypasses the if statment!

can sum 1 plz help me on this as im baffled!
and if u really want to help out is there away to store the prices in a database so they can be modified?? but just getting an if stament like that 2 work would be great!

Thx in advance!First question is, what is shoppingCartId? Are you sure that is set to a valid shopping cart id?

Second, if you run the query in Query Analyzer, do you get the proper result there?

Regarding your final question about storing prices in a database so they can be modified, yes there is. Any data in a database can be modified, assuming that you have permissions to do so. You can use an UPDATE statement to change them.

Is that what you meant?

Don
Yep the sql statement works it calculates the weight and passes it on!

however its not useing the if statment after

return amount its just bypassing that big if statment how do u get it so it recaculates the amount varible using that big ass if statment??

what i meant with the database editing is how would u go about it cos u would have 2 compare the weight against a column in the databse?

say the column in the database

(weight int 4) (price money)
1000 £3.50
2000 £6

and the combined weight off the product was say 1500 so that would be the price for the 2000 row so how would u do that?? in the sql statemmnet i assume but i only now how to recive stuff if its precise.

Is that clearer??
can any1 help?? dont care about the database bit but how do i get that if statment working? thx!

Stuck

Ok,

I got this page (with a datagrid on it) that I hit a button on and it opens
a new page (popup). In that popup I have to option to delete the record that
got me there, or change it.. whatever.

Ok when I am done and close the popup and give focus back to the parent
form...

How can I refresh it so that the changes are shown.. or rebind it or
whatever.. how do I tell the form to do something once the child (popup) is
closed?

thanksYou can use "opener" object before closing the popup form.

like opener.MYFORM.submit(); or opener.refresh;
George.

"HalaszJ" <halaszj@.charter.net> wrote in message
news:eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it
opens
> a new page (popup). In that popup I have to option to delete the record
that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup)
is
> closed?
> thanks
You can use "opener" object before closing the popup form.

like opener.MYFORM.submit(); or opener.refresh;
George.

"HalaszJ" <halaszj@.charter.net> wrote in message
news:eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it
opens
> a new page (popup). In that popup I have to option to delete the record
that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup)
is
> closed?
> thanks
You need some Java Script, to reload the grid's page
before closing your popup try :

opener.document.location.href=opener.document.loca tion.href

or

top.opener.navigate(top.opener.document.location.h ref)

Hope this helps

Eduardo

"HalaszJ" <halaszj@.charter.net> wrote in message news:<eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl>...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it opens
> a new page (popup). In that popup I have to option to delete the record that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup) is
> closed?
> thanks
You need some Java Script, to reload the grid's page
before closing your popup try :

opener.document.location.href=opener.document.loca tion.href

or

top.opener.navigate(top.opener.document.location.h ref)

Hope this helps

Eduardo

"HalaszJ" <halaszj@.charter.net> wrote in message news:<eIGGYKAmDHA.2140@.TK2MSFTNGP09.phx.gbl>...
> Ok,
> I got this page (with a datagrid on it) that I hit a button on and it opens
> a new page (popup). In that popup I have to option to delete the record that
> got me there, or change it.. whatever.
> Ok when I am done and close the popup and give focus back to the parent
> form...
> How can I refresh it so that the changes are shown.. or rebind it or
> whatever.. how do I tell the form to do something once the child (popup) is
> closed?
> thanks

stuck and confused

Ok, here is my scenario, I have an asp web app that i'm converting to .net.
The app reads files and loads the data into SQL db, now, in my file it has
numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads the
files into the db and I run query analyzer I see the numbers as they are in
the file, but when I upload the same file in my .net version of the app, I
see the numbers like this in query anaylzer: 125.25636363, 3363.3320001,
69.0000001. The columns are defined as floats in the table, and I changed th
e
types in the code from float to double and even tried decimal, but no luck,
any suggestions on how to get the numbers to show correctly from my .NET app
when I run query anaylzer?how are you going from the text file to code to the database?
are you using xxx.Parse() (like float.Parse()) on a string or something...
Karl
http://www.openmymind.net/
http://www.fuelindustries.com/
"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
> Ok, here is my scenario, I have an asp web app that i'm converting to
> .net.
> The app reads files and loads the data into SQL db, now, in my file it has
> numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads the
> files into the db and I run query analyzer I see the numbers as they are
> in
> the file, but when I upload the same file in my .net version of the app, I
> see the numbers like this in query anaylzer: 125.25636363, 3363.3320001,
> 69.0000001. The columns are defined as floats in the table, and I changed
> the
> types in the code from float to double and even tried decimal, but no
> luck,
> any suggestions on how to get the numbers to show correctly from my .NET
> app
> when I run query anaylzer?
>
the code isn't doing float.parse(), i picked the app up from a former
developer and trying to fix the mess left behind. He's reading the text
files, creating a datatable, then inserting that into the table. in the
datatable, he has something like this:
aColumn = new DataColumn(SALESAMOUNT, System.Type.GetType("System.Single"));
"Karl Seguin [MVP]" wrote:

> how are you going from the text file to code to the database?
> are you using xxx.Parse() (like float.Parse()) on a string or something..
.
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
>
>
is he then doing somethng like
DataRow row = databable.NewRow();
row["SalesAmount"] = someValue;
or
row[12] = someValue;
?
if so, what type is someValue? a string?
Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
> the code isn't doing float.parse(), i picked the app up from a former
> developer and trying to fix the mess left behind. He's reading the text
> files, creating a datatable, then inserting that into the table. in the
> datatable, he has something like this:
> aColumn = new DataColumn(SALESAMOUNT,
> System.Type.GetType("System.Single"));
>
> "Karl Seguin [MVP]" wrote:
>
like this:
DataRow row = databable.NewRow();
row["SalesAmount"] = arr[1].toString();
"Karl Seguin [MVP]" wrote:

> is he then doing somethng like
> DataRow row = databable.NewRow();
> row["SalesAmount"] = someValue;
> or
> row[12] = someValue;
> ?
> if so, what type is someValue? a string?
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
>
>
well...so far everything looks ok...
can you put a breakpoint and see what format arr[1] is in. My guess is that
it's happening when the value is first loaded from the text file (perhaps
into arr[1]). Can you provide more chunks of code?
Karl
http://www.openmymind.net/
"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
> like this:
> DataRow row = databable.NewRow();
> row["SalesAmount"] = arr[1].toString();
>
> "Karl Seguin [MVP]" wrote:
>
I did that, and all the way through I can see the number being uploaded as
125.25, so could it be a SQL thing transforming the numbers or something I'm
missing?
"Karl Seguin [MVP]" wrote:

> well...so far everything looks ok...
> can you put a breakpoint and see what format arr[1] is in. My guess is tha
t
> it's happening when the value is first loaded from the text file (perhaps
> into arr[1]). Can you provide more chunks of code?
> Karl
> --
> http://www.openmymind.net/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
>
>
If the SQL column is a float, you might wanna try changing it to a decimal.
You'll also want to make sure your SqlCommand has a decimal type. Something
like:
command.CommandType = CommandType.Text;
command.CommandText = "INSERT INTO SomeTable (SalesAmount) VALUES
(@.SalesAmount)";
command.Parameters.Add("@.SalesAmount", SqlDbType.Decimal);
command.Parameters[0].SourceColumn = "SalesAmount";
Karl
--
http://www.openmymind.net/
"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:5EF97DBC-4C69-4B07-A484-9A95230A8208@.microsoft.com...
>I did that, and all the way through I can see the number being uploaded as
> 125.25, so could it be a SQL thing transforming the numbers or something
> I'm
> missing?
>
> "Karl Seguin [MVP]" wrote:
>
I can't change the column in the db due to it "replication" to other tables,
etc. I did make it a decimal in the SQLCommand, but still no go. I can see
it in the table correctly via enterprise manager, but when i do a query via
Query analzer is where I'm seeing the incorrect number format.
"Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u013J8xPGHA.3016@.tk2msftngp13.phx.gbl...
> If the SQL column is a float, you might wanna try changing it to a
> decimal. You'll also want to make sure your SqlCommand has a decimal type.
> Something like:
> command.CommandType = CommandType.Text;
> command.CommandText = "INSERT INTO SomeTable (SalesAmount) VALUES
> (@.SalesAmount)";
> command.Parameters.Add("@.SalesAmount", SqlDbType.Decimal);
> command.Parameters[0].SourceColumn = "SalesAmount";
>
> Karl
> --
> http://www.openmymind.net/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:5EF97DBC-4C69-4B07-A484-9A95230A8208@.microsoft.com...
>
I don't think there's a good solution in that case. It would seem that the
person who designed the database might not have understood what Floats are.
Floating points are an approximate representation of your number - not all
values can't be represented. Decimals are used for exact numbers.
You might want to check out:
http://msdn.microsoft.com/library/d... />
3_6mht.asp
Karl
--
http://www.openmymind.net/
"CsharpGuy" <me@.me.com> wrote in message
news:e7jOI55PGHA.2108@.TK2MSFTNGP10.phx.gbl...
>I can't change the column in the db due to it "replication" to other
>tables, etc. I did make it a decimal in the SQLCommand, but still no go. I
>can see it in the table correctly via enterprise manager, but when i do a
>query via Query analzer is where I'm seeing the incorrect number format.
>
> "Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
> net> wrote in message news:u013J8xPGHA.3016@.tk2msftngp13.phx.gbl...
>

stuck in a loop

Hi

I try to use this piece of code, but the page seems to get stuck in the loop. What am I doing wrong here?

Function NumberOfLinesInFile()
Dim path As String = Server.MapPath("row.txt")
Dim sr As StreamReader = New StreamReader(path)
Dim i As Integer
i = 0
Do While sr.Peek() >= 0
i = i + 1
Loop
sr.Close()
Return i
End Function

Regards

Mhello, what if sr.Peek() is always >= 0 ? check the values returned by sr !!!
The Peek function does not move to the next character, it only consumes it. Try using the sr.Read() instead.

hope this helps,

sivilian

stuck in the beginning!

Hi!
I tried to create my first ASP .NET application using VBScript, i recenetly installed .NET, i added some controls like a textbox, a button and few labels. When i try to view the web page, only the labels can be seen but not any other controls. When i try to debug it, i get a messadge saying that i need to install some components. Cany anyone help me out? Thank you.First of all, ASP.NET uses VB.NET not VBScript but I assume that it was just a typo on your behalf (confusing ASP and ASP.NET). In order to get it to work you'll need to install ASP.NET on your IIS server, as follows:
1. go to the command prompt (Start, Run, cmd.exe)
2. go to the Windows\Microsoft.NET\Framework\v1.1.4322 folder
3. execute aspnet_regiis.exe /i

In order to do this, make sure the .NET Framework is installed on the system (available through Windows Update or via the MSDN website). I assume you're using IIS to develop ASP.NET apps in this case. To view your pages, save them in the inetpub\wwwroot folder and go to http://localhost/thepage.aspx (replace theplace.aspx of course) to view the result.
Thanks a lot man. This will get me going. And i apologize for the typo. Thanks again.

stuck in the beggining..

Hi,

Why is it that everytime i try to make a new asp.net page and then put any <% %> code it generates errors? After a couple times of trying to run it i just copy and pasted a snippet of code from a tutorial and still no luck. Am i just forgetting to do something?

thankx.

Pleeze pardon my noobish-ness, just started migrating to asp.net from phpHi,

I am new too and may have had the same prolem. If you are trying to test your Javascript from your development server you have to run some Javascript 'client' tools.

The error mesage is was receiving was something like 'cannot find system. js file' or something like that. Anyway, you just need to run the client stuff. Heres the replied I got for my problem like this...


Run aspnet_regiis.exe -c
on that server. Your client-side scripts are not installed into the \aspnet_client folder for the domain in question.

This was really helpful too and the site's pretty good.


what's the exact error?

sounds like you need the aspnet_client stuff. running aspnet_regiis.exe can help you out there

------------------------
RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unreadable
Jason Brown - MVP, IIS

I hope that this has helped you.
Hello, well you must know how to create ur asp.net page, it doesn't only start with <% %>, it needs <%@. Page ...... > and other tags too.
Check this page:Creating Our First ASP.NET Web Page

Good Luck.
Thanks both of yall, i have it running now. ^_^
Glad to help you our friend,

Good Luck.

Stuck on a Regular Expression...!?

I have the following rule in my web.config that is used in a url redirect

<RewriterRule>

___<LookFor>~/Category/(\w+)\.aspx></LookFor>

___<SendTo><![CDATA[~/Page.aspx?m=13&i=$1]]></SendTo>

</RewriterRule>

This works fine. I'm trying to do a slightly more complex one but I'm having problems with the correct expression and was hoping someone could help.

I'm trying to set it up so it when you browse to /Category/Product/892_23.aspx

It goes to Page.aspx?m=13&c=892&i=23 (eg category 892 and item 23)

The categoryID and productID can be any number of digits, that is why I have put in the '_' so I can see where one ends and the other starts.

What I'm not sure about is how to create the expression that will split them up��

Any help would be great. Thanks

I'm writing this off the top of my head, so I may get it wrong. However, try the following:
<RewriterRule>
<LookFor>~/Category/Products/(\d+)_(\d+)\.aspx></LookFor>
<SendTo><![CDATA[~/Page.aspx?m=13&c=$1&i=$2]]></SendTo>
</RewriterRule>

Thanks for that, that worked first time...

I'm sorry to hyjack my own thread but I have one last question.

I have the following site structure:

SiteRoot/Page.aspx

Page.aspx loads other content pages (ascx) into it based on parameters passed in the querystring.

Eg. Page.aspx?m=1&i=1 would display the "News" module (moduleID=1) and news item 1 (newsID=1)

This works fine. I want to implement URLrewriting. I have followed this articlehttp://msdn.microsoft.com/library/?url=/library/en-us/dnaspp/html/urlrewriting.asp and have hit a problem.
I have set up in my web.config file rules:

<RewriterRule>
___<LookFor>~/News/(\w)\.aspx</LookFor>
___<SendTo>~/Page.aspx?m=1&i=$1</SendTo>
</RewriterRule>

This works fine so when I type MySite/News/1.aspx into the browser it rewrites to MySite/Page.aspx?m=1&i=1 and shows the page.

The problem is the images on the News Item page. They have <img src='images/image1.jpg'> this shows fine on MySite/Page.aspx?m=1&i=1 (Page.aspx is on the root). However when I go to MySite/News/1.aspx, the source for the image is broken. It is now looking for the images folder in the News folder which does not exist.

Do I have to put <img src="http://pics.10026.com/?src=~/images/image.jpg" runat='server'/> on every image reference, or is there another way around this.

Thanks again


ricc wrote:

The problem is the images on the News Item page. They have <img src='images/image1.jpg'> this shows fine on MySite/Page.aspx?m=1&i=1 (Page.aspx is on the root). However when I go to MySite/News/1.aspx, the source for the image is broken. It is now looking for the images folder in the News folder which does not exist.

Do I have to put <img src="http://pics.10026.com/?src=~/images/image.jpg" runat='server'/> on every image reference, or is there another way around this.

Yes, I approved your new thread wherein you asked the same question.
I didn't provide an answer, because frankly I don't know how other developers deal with this problem. To me, adding a tilde to the start of all links would be a royal pain. If you would like to see how I deal with this problem, please see my reply in the following thread:
UserControls and relative links

stuck on a REGEX (\S[^\s/>]*)

I'm trying to find the opening < and the text of a tag (without the
attributes or closing tags)
This is what I'm using:
(\S[^\s/>]*)
Which, I think, reads as:
(any number of non-whitespace characters [up to a space, /, or >])
Is that correct? I can't get it to work.
If my text is:
<tag
then it returns "<tag" which is what I want.
However, if I have:
<tag/ or <tag>
it instead matches "/" or ">" respectively.
Why?darrel wrote:
> I'm trying to find the opening < and the text of a tag (without the
> attributes or closing tags)
> This is what I'm using:
> (\S[^\s/>]*)
> Which, I think, reads as:
> (any number of non-whitespace characters [up to a space, /, or >])
> Is that correct? I can't get it to work.
> If my text is:
> <tag
> then it returns "<tag" which is what I want.
> However, if I have:
> <tag/ or <tag>
> it instead matches "/" or ">" respectively.
> Why?
>
In my brief testing, when run against "<tag/" it first matches "<tag" -
then the next match is "/". The second match matches "/" because it
matches the \S character class.
Post some examples of how you want the regex to behave, and maybe
someone can help put one together.
mikeb
> In my brief testing, when run against "<tag/" it first matches "<tag" -
> then the next match is "/". The second match matches "/" because it
> matches the \S character class.
But shouldn't this: [^/] stop it from doing that?
Here's how I want the regex to behave:
I want to find the first 'word' in the string. this would be any number of
characters in a row up to (but not including) a space, a new line, or a / or
>
so in this:
"hello there, how are you"
it should match 'hello'
in this:
"<blockquote>hello there, how are you"
it should match '<blockquote'
Thanks!
-Darrel

> But shouldn't this: [^/] stop it from doing that?
Aha. Mike, you are correct!
Here's what's happening. If this is my text:
<blockquote>monkey</blockquote>
and this is my Regex:
\S[^>]*
It returns these matches:
<blockquote
>monkey</blockquote
>
So, it's returning the last match, I suppose. This is where I get lost. How
do I get it to ONLY return the first match?
Got it!
The problem was the very next group I was using.
I had this:
(\S[^\s/>]*)
but had to add another group:
(\s|\n[^\S>]*)|(> ))
which checks for whitespace/new lines OR a closing tag.
-Darrel
Use the Match Class of the regular expression object
Dim m as Match = yourRegEx.Match(string)
m will return the first match
"darrel" wrote:

>
> Aha. Mike, you are correct!
> Here's what's happening. If this is my text:
> <blockquote>monkey</blockquote>
> and this is my Regex:
> \S[^>]*
> It returns these matches:
> <blockquote
> So, it's returning the last match, I suppose. This is where I get lost. Ho
w
> do I get it to ONLY return the first match?
>
>
>

stuck on a REGEX (\S[^\s/>]*)

I'm trying to find the opening < and the text of a tag (without the
attributes or closing tags)

This is what I'm using:

(\S[^\s/>]*)

Which, I think, reads as:

(any number of non-whitespace characters [up to a space, /, or >])

Is that correct? I can't get it to work.

If my text is:

<tag

then it returns "<tag" which is what I want.

However, if I have:

<tag/ or <tag
it instead matches "/" or ">" respectively.

Why?darrel wrote:
> I'm trying to find the opening < and the text of a tag (without the
> attributes or closing tags)
> This is what I'm using:
> (\S[^\s/>]*)
> Which, I think, reads as:
> (any number of non-whitespace characters [up to a space, /, or >])
> Is that correct? I can't get it to work.
> If my text is:
> <tag
> then it returns "<tag" which is what I want.
> However, if I have:
> <tag/ or <tag>
> it instead matches "/" or ">" respectively.
> Why?

In my brief testing, when run against "<tag/" it first matches "<tag" -
then the next match is "/". The second match matches "/" because it
matches the \S character class.

Post some examples of how you want the regex to behave, and maybe
someone can help put one together.

--
mikeb
> In my brief testing, when run against "<tag/" it first matches "<tag" -
> then the next match is "/". The second match matches "/" because it
> matches the \S character class.

But shouldn't this: [^/] stop it from doing that?

Here's how I want the regex to behave:

I want to find the first 'word' in the string. this would be any number of
characters in a row up to (but not including) a space, a new line, or a / or

so in this:

"hello there, how are you"

it should match 'hello'

in this:

"<blockquote>hello there, how are you"

it should match '<blockquote'

Thanks!

-Darrel
> But shouldn't this: [^/] stop it from doing that?

Aha. Mike, you are correct!

Here's what's happening. If this is my text:

<blockquote>monkey</blockquote
and this is my Regex:

\S[^>]*

It returns these matches:

<blockquote
>monkey</blockquote

So, it's returning the last match, I suppose. This is where I get lost. How
do I get it to ONLY return the first match?
Got it!

The problem was the very next group I was using.

I had this:

(\S[^\s/>]*)
but had to add another group:
(\s|\n[^\S>]*)|(>))
which checks for whitespace/new lines OR a closing tag.
-Darrel
Use the Match Class of the regular expression object
Dim m as Match = yourRegEx.Match(string)
m will return the first match

"darrel" wrote:

> > But shouldn't this: [^/] stop it from doing that?
> Aha. Mike, you are correct!
> Here's what's happening. If this is my text:
> <blockquote>monkey</blockquote>
> and this is my Regex:
> \S[^>]*
> It returns these matches:
> <blockquote
> >monkey</blockquote
> So, it's returning the last match, I suppose. This is where I get lost. How
> do I get it to ONLY return the first match?
>
>

Stuck on If Then Statement With Control

I am just really getting into learning all this with ASP and have been head deap into books, lol. The thing I am not sure about is this. I am using the .NET controls on my page but I do not understand how to take what I have below and then do a if then statement on it.

So another words here is my code:

<asp:DataListID="DataList1"runat="server"DataSourceID="SqlDataSource1">

<ItemTemplate>

<asp:LabelID="SpringBCT1Label"runat="server"

Text='<%# Eval("SpringBCT1") %>'/>

<br/>

</ItemTemplate>

</asp:DataList>

Now how can I take what the results were that came back for that and do a if then statement on it? I need a way to look at the data. The data from the database will either be "On Time" or "Delayed"

So I want to do a...

If whatever = "On Time" then

Else

' do something else here

I am just not sure how to convert that control into a string of data. Code example would be great.

Big thanks in advance!

Is "whatever" the results of Eval("SpringBCT1") ?

Depending on how/when u need this value you can do two things. The first (and easiest) is just to attach an event to your SprintBCT1Label like: OnPreRender="GetMyTextValue"

protected void GetMyTextValue(object sender, EventArgs e){

Label label = sender as Label;

if (label == null)

return;

Response.Write(label.Text);//do something useful with it
}

and then you can just read out the value of the label every time the event handler fires for each label. Alternatively you can enumerate through the data lists items.

foreach (DataListItem item in DataList1.Items){

Label bct1Label = item.FindControl("SpringBCT1") as Label;

if (bct1Label == null)

continue;

Response.Write(bct1Label.Text);//do something useful
}

Hope that helps.


Yes the "watever" would be the results. I have selected to do this all in VB. The above has me lost... lol. Could you go into a bit more detail?

Thanks!


Here is how I would like to do it.. This is the way I did it in pure VB.NET

Dim MyConnAs ADODB.Connection

Dim MyRecSetAs ADODB.Recordset

Dim strTitleAsString

MyConn =New ADODB.Connection

MyConn.ConnectionString ="Provider=sqloledb;Data Source=D032379\SQLEXPRESS;Initial Catalog=CutOffGrid;Integrated Security=True"

MyConn.Open()

MyRecSet = MyConn.Execute("SELECT * FROM Grids")

DoUntil MyRecSet.EOF

strTitle = MyRecSet.Fields.Item("SpringBCT1").Value

If strTitle ="On Time"Then

SpringBCT1.Text ="On Time"

Else

SpringBCT1.Text ="Delayed"

EndIf

MyRecSet.MoveNext()

Loop

MyConn.Close()

Problem is this does not seem to work in ASP.NET. It does not like these items:

Dim MyConnAs ADODB.Connection

Dim MyRecSetAs ADODB.Recordset

MyConn =New ADODB.Connection

And I have no idea as to how to do this then :-(

Any ideas?


Because they're old ADO objects not ADO.Net...

you can look throw the datalist like this:

Dim strTitle

For Each item As DataListItem In DataList1.Items

Dim bct1Label As Label = TryCast(item.FindControl("SpringBCT1"), Label)

If bct1Label Is Nothing Then
Continue For

End If

strTitle = bct1Label.Text

if NOT strTitle = "On Time" Then 'not sure that's how you do != in vb
bct1Label.Text = "Delayed"
End If
Next

Do you actually need the datalist or have you just done that because you experimenting?

See MSDN docs on SqlDataSource, SqlConnection and SqlDataReader


Ok ffigured it out. :-)

This is how I did it with the backend VB page...

Dim conpubsAs SqlConnection

Dim cmdselectauthorsAs SqlCommand

Dim dtrauthorsAs SqlDataReader

Dim sp1AsString

Dim sp2AsString

conpubs =New SqlConnection("Data Source=D032379\SQLEXPRESS;Initial Catalog=CutOffGrid;Integrated Security=True")

conpubs.Open()

cmdselectauthors =New SqlCommand("select * from Grids", conpubs)

dtrauthors = cmdselectauthors.ExecuteReader()

While dtrauthors.Read()

sp1 = (dtrauthors("SpringBCT1")).ToString

sp2 = (dtrauthors("SpringBCT2")).ToString

SpringBCT1.Text = sp1

SpringBCT2.Text = sp2

EndWhile

dtrauthors.Close()

conpubs.Close()

Thanks for the help!


You can also do this way,

<asp:LabelID="SpringBCT1Label"runat="server" Text='<%#IIf((Eval("SpringBCT1").ToString() = "On Time"), "On Time", "Delayed") %>'/>

Thanks

-Mark post(s) as "Answer" that helped you

stuck on empty page after sending email with.........mailto:"email address here"

Hi, i have code that opens an Ms outlook new email message window on myGridviews' ItemUpdated event. I did this because of the easy with which users will find email addresses to send messages to with out the pain of remembering or cramming the so many company employee email accounts. After sending the email, outlook closes which is okay to me but the problem is, i now remain with a blank page instead of returning to the page with my Gridview from where i fired the update event that opened outlook. I wish i had away of posting or redirecting to another page or even better returning to the same page from ItemUpdated event that opened outlook was fired from. Iam not sure if this explaination is clear to any one reading it but below is the code iam talking about.

ProtectedSub GridView1_RowUpdated(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.GridViewUpdatedEventArgs

Response.Redirect(mailto:my-email-account@dotnet.itags.org.ppp.co.ug

Response.redirect("Default.aspx") 'Why is this line of code not redirecting to Default.aspx

END SUb

Option Two: How can i open outlook when an event fires without using Response.Redirect because that is exactly what what is bringing me all this mess.

Dont use a Response.Redirect(), just use an HREF...


Your first response.redirect changes the page you are on, so the second one never fires.

Why not just show the email address when your user updates the row? Or use a pop-up to display the email address for the user to click.

Try creating a hidden iframe and setting the location of the iframe to the mailto address. This might do the trick, but I haven't tested it.

--JJ


This is my scenerio. when a row is updated, basically we are talking about a name field which is initially null being filled with an employee name. So when the user clicks update after typing the employee name in this field, On the itemUpdate event of this particular Gridview, outlook opens and then the administrator doing the update should lookup the email address in outlook of the same employee whose name was entererd prevously. The aim is to send a notification email that he has been assigned a record he/she should take charge of.

So at the end of the operation, a record should have been updated and an outlook email(not automatic) should have been send to the employee whose name was entered in the Gridviews' name field.


How do you use HREF in an event handle sub procedure.


By HREF, Curt means a HyperLink. You need to use a hyperlink and open a popup to send the mail

<a href="http://links.10026.com/?link=my-email-account@.ppp.co.ug" target="_blank">Send Mail</a>

Thanks

Stuck on debugging problem on ASP.net 2.0 using VS 2005

It really make me crazy, I put a breakpoint on line 1, when the debugging process started, it should be expected to loop through 1 to 4 step by step on pressing F10, however, it is really really weird that the pointer is jump to line 3 after I press F10, and then line 2 and then go back to line 3, line 4 and back to line 2 ... It is different for every time, sometimes it loops through the whole procedure, but then jump back to the top of the procedure and loops one more time, sometimes it is normal to loop through the procedure just one time ONLY. Does anyone get any idea what is actually happening here?

Thanks if there is any kind reply.

protected void XXX (object sender, EventArgs e)

{

1<-- breakpoint

2

3

4

}

F10 steps over, that's why it's skipping parts of your code. You should use F11 to go step by step.
depends on how the loop is constructed , what the values are that control the loop, etc..
- post the actual code - then we could help more
.
If there are any control structures in your loop code, this would happen. If you don't have any control structures in your code, F10should just go line by line. One other possibility is that the executable you are debugging and the code are out of sync. Try doing a rebuild and see if that resolves the issue.

protected void CompanyListGridView_SelectedIndexChanged(object sender, EventArgs e)
{
// Disable error message since the user has selected the company
lblErrorMessage.Visible = false;

// Clear manufacturing order list
Clear_ManufacturingOrderEntryList();
Clear_DestinationList();
Clear_DepartmentList();

if (CompanyListGridView.SelectedDataKey == null)
return;

// Get company ID
long COM_ID = Convert.ToInt64(CompanyListGridView.SelectedDataKey.Value);

Company COMPANY = Company.GetCompaniesByCompanyID(COM_ID);

if (COMPANY == null)
return;

// Show details on textboxes
txtCOM_ID.Text = String.Format("{0:LF0000}", COMPANY.COM_ID);
txtCOM_CHT.Text = COMPANY.COM_FN;
txtMO_POD.Text = DateTime.Now.ToShortDateString();
//txtMO_PO.Text = "Plese Input PO Number";
txtMO_DD.Text = DateTime.Now.AddDays(7).ToShortDateString();

// Enable textboxes for input
txtMO_PROJ.Enabled = txtMO_HD.Enabled = txtMO_PO.Enabled = txtMO_POD.Enabled = txtMO_DD.Enabled = true;
txtMO_REM.Enabled = ddlMO_DEST.Enabled = ddlMO_DEPT.Enabled = true;

// Show create and cancel buttons
btnCreateMO.Visible = btnCancelMO.Visible = true;

// Bind drop down list
Bind_DestinationList(COM_ID);
Bind_DepartmentList();
Bind_ComDeptList(COM_ID);

// Hide Customer List
CustomerListFieldset.Visible = false;
}

This is the procedure I wrote, when I click on one of the row in Company List Gridview, then this function will be triggered. I tested it yesterday, no problem has been found. But I run this today, the problem is appeared again. The cursor jumps around the code without order, and the second time I test it, it loops through twice continuously.

Thanks for all kindly help.


Is this a problem of visual studio 2005 ? or ASP.net 2.0 or my fault ?


It sounds like this method is getting triggered twice. You might check to make sure that this method is not registered with more than one event. Also check for code elsewhere on the page that could cause the method to be manually called.

If you are using Visual Studio, you might take a look at the stack as you are walking through the code and see what caused the method to be called each time you take a step. If the parent method on the stack that caused the method to be called is changing, that is probably what is happening.

To open the call stack window, go to Debug -> Windows -> Callstack


The stack is showing the following message

App_Web_dqqvphy9.dll!Erms_MO01.CompanyListGridView_SelectedIndexChanged(object sender = {System.Web.UI.WebControls.GridView}, System.EventArgs e = {System.EventArgs}) Line 74

Only one message is showing until debugging process for the procedure is finished


Hmm. That is the only thing in the stack? Nothing higher?

Tell you what. Post the XML for your GridView. I'd also like to see your Page_Load method in the code behind.


<td nowrap style="vertical-align:top">
<fieldset id="CustomerListFieldset" runat="server" visible="false">
<legend>Customer List</legend>
<br />
<asp:ObjectDataSource ID="CompanyListDataSource" runat="server" TypeName="Erms.BusinessLogicLayer.Company"
SelectMethod="GetAllCompanies">
</asp:ObjectDataSource>
<asp:GridView ID="CompanyListGridView" runat="server" DataSourceID="CompanyListDataSource" DataKeyNames="COM_ID"
AutoGenerateColumns="False" GridLines="None" ShowHeader="false" ShowFooter="false" OnSelectedIndexChanged="CompanyListGridView_SelectedIndexChanged" >
<Columns>
<asp:CommandField ButtonType="Image" ShowSelectButton="true" SelectImageUrl="images/BtnIconEdit.gif" />
<asp:TemplateField>
<ItemStyle Wrap="false" />
<ItemTemplate>
<%# String.Format("{0:LF0000}", DataBinder.Eval(Container.DataItem, "COM_ID")) %>
<%# DataBinder.Eval(Container.DataItem, "COM_FN") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" wrap="false" />
<EmptyDataTemplate>
<asp:Label ID="Lable1" runat="server">There is no company record in list</asp:Label>
</EmptyDataTemplate>
</asp:GridView>
<br />
</fieldset>

</td>

// My Page_Load code behind is also empty

protected void Page_Load(object sender, EventArgs e) {}

==========================================

Since I used object data source for company list gridview data binding, so there is no method I should have to specify in page load. When the page loads, the gridview will bind to the data

ummm ... there are a lot of different patterns to load the procedure

1. Loops through the whole procedure twice if I click on the company list gridview

2. Normally loops through the whole procedure one time ONLY

3. Load 2 times for each line, that means when I press F10, it goes to first line --> F10 --> First line --> F10 -->

Second line --> F10 --> Second line --> F10 --> Third line --> F10 --> Third line ... until the end of the procedure

4. Randomly jump between lines but actually it does have pattern

Line 1

Line 2

Line 3

Line 4

Line 5

Line 6

Line 7

Line 8

First, it goes to line 1, line 2, line 3, line 4 and then line 1, line 5, line 2, line 6, line 3, line 7, line 8, line 5 ..... ~_~"

it really really make me crazy and I can't write for the following things ... HELP PLEASE

Stuck on datagrid

hi all, thanks for the last help...

now i am stuck at this step 6 of the following section

http://www.asp.net/webmatrix/tour/section3/formatdatagrid.aspx

When the Collection Editor dialog box appears, it does not show like that in the tutorial, it does not show any BoundField at all.

I check everything and i am sure i did all steps accordingly.

Is the tutorial kinda out-dated? Some of the pictures snapshots in the tutorials do not match the real things. Like when I was working on the Data Tab in the Workspace window, it showed a different set of icons. The same thing happened when creating a database. The tutorial does not mention that I have to choose between Access and SQL database. So I chose the later. Not to mention the Orders, OrdersDetail tables. Does it make any difference at all? So what's database type used in WebMatrix?

Thanks again
mitoshieIf you downloaded WebMatrix recently, then there is a good chance that the tutorial is out of date, since a new version of WebMatrix was released recently.

You might try re-posting this in theWebMatrix forum here.

Stuck on some code

Hello all:

Would appreciate some help. I need to fill the session collection with the results from TWO tables as a datarelation and this is where I am stuck. Filling the results from one table is easy but how do i do this with the two tables.

I tried modifying the code in the For statment as follwos but it would not work.

foreach(DataRow r in dr)

public static SessionCollection GetEmployeeGridEntries( string SelDate)
{

DataSet ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[Web.Global.CfgKeyConnString],"SP_GetEmployeeWorkedGrid",
Convert.ToDateTime(SelDate));

ds.Tables[0].TableName = "Employee";
ds.Tables[1].TableName ="EmployeeRecords";

DataColumn Parent;
DataColumn Child;

Parent=ds.Tables[0].Columns["Employee_Number"];
Child =ds.Tables[1].Columns["Stat_Employee"];

DataRelation dr = new DataRelation("EmployeeGroup", Parent,Child,false);ds.Relations.Add(dr);

SessionCollection mysession = new SessionCollection();
foreach(DataRow r in ds.Tables[0].Rows) //??Stuck at this point
{
MySession prj = new MySession();
prj.EmployeeName =r["EmployeeName"].ToString();
prj.Hours = Convert.ToDecimal(r["Stat_Hours"]);
mysession.Add(dr);
}

return mysession;
}Hi Bryan,
You cud try something with the GetChildRows Method of the parent table

foreach (DataRow r in ds.Tables[0].Rows)
{
MySession prj = new MySession();
prj.EmployeeName =r["EmployeeName"].ToString();
prj.Hours = Convert.ToDecimal(r["Stat_Hours"]);

DataRow[] childr;
childr = r.GetChildRows("EmployeeGroup");
foreach (DataRow childRow in childr)
{
prj.ChildTblField1 = childRow["FieldName1"].ToString();
.
.
}
}

The above dots in the inner for loop represent other fields you may need to extract from the table.

Hope that helps.

Regards,
Hello -

Just wondering if the datarelation couldn't be accomplished through
a query with an aggregate?

Please advise on what you are really trying to accomplish.

thanks
tony
Tony:

I am trying to utilize the Hierargrid control in a heavily midifed timetracker application. The web page calls a class to fill a datagrid. Here is the unmodified code from the timetracker application. In my application i want to modify the GetProjects() so that a data relation is used to fill the collection.

public class Project
{
private SessionCollection _categories;
private string _description;
private DateTime _estCompletionDate;
private decimal _estDuration;
private int _managerUserID;
private string _managerUserName;
private UsersCollection _members;
private string _name;
private int _projectID;

public Project()
{
}

public Project(int projectID)
{
_projectID = projectID;
}

public Project(
int projectID,
string name,
string description,
int managerUserID,
DateTime estCompletionDate,
decimal estDuration)
{
_projectID = projectID;
_name = name;
_description = description;
_managerUserID = managerUserID;
_estCompletionDate = estCompletionDate;
_estDuration = estDuration;
}

public SessionCollection Categories
{
get{ return _categories; }
set{ _categories = value; }
}

public string Description
{
get{ return _description; }
set{ _description = value; }
}

public DateTime EstCompletionDate
{
get{ return _estCompletionDate; }
set{ _estCompletionDate = value; }
}

public decimal EstDuration
{
get{ return _estDuration; }
set{ _estDuration = value; }
}

public int ManagerUserID
{
get{ return _managerUserID; }
set{ _managerUserID = value; }
}

public string ManagerUserName
{
get{ return _managerUserName; }
set{ _managerUserName = value; }
}

public UsersCollection Members
{
get{ return _members; }
set{ _members = value; }
}

public string Name
{
get{ return _name; }
set{ _name = value; }
}

public int ProjectID
{
get{ return _projectID; }
set{ _projectID = value; }
}

//*********************************************************************
//
// Retrieves a list of projects based on the user's role
//
//*********************************************************************

public static ProjectsCollection GetProjects(int userID, string role)
{
string firstName = string.Empty;
string lastName = string.Empty;

DataSet ds = SqlHelper.ExecuteDataset(
ConfigurationSettings.AppSettings[Web.Global.CfgKeyConnString],
"TT_ListProjects", userID, Convert.ToInt32(role));

ProjectsCollection projects = new ProjectsCollection();
foreach(DataRow r in ds.Tables[0].Rows)
{
Project prj = new Project();
prj.ProjectID = Convert.ToInt32(r["ProjectID"]);
prj.Name = r["ProjectName"].ToString();
prj.Description = r["Description"].ToString();
prj.ManagerUserID = Convert.ToInt32(r["ManagerUserID"]);
prj.ManagerUserName =
TTUser.GetDisplayName(Convert.ToString(r["UserName"]), ref firstName, ref lastName);
prj.EstCompletionDate = Convert.ToDateTime(r["EstCompletionDate"]);
prj.EstDuration = Convert.ToDecimal(r["EstDuration"]);
projects.Add(prj);
}
return projects;
}
Thanks Shravan.

I am a little stuck on this aspect of your code, would you be able to explain. Namely this line

prj.ChildTblField1 = childRow["FieldName1"].ToString();

It returns a error that fieldname1 can not be found in the table Employee. It appears not to be referncing table 1, but still referencing table 0.

DataRow[] childr;
childr = r.GetChildRows("EmployeeGroup");
foreach (DataRow childRow in childr)
{
prj.ChildTblField1 = childRow["FieldName1"].ToString();
.
.
}
}
Bryan,
By naming FieldName1 in this line
prj.ChildTblField1 = childRow["FieldName1"].ToString();

I meant that you would use the field names of the second table and you should be knowing the its field names (of your second table) which I do not have any knowledge about. Also the ChildTblField1 referrs that its a property in your prj whose value is set by the expression or code on the right hand side of the '=' sign in the line above.

Also, How did it refer FieldName1 in table Employee. Its a field of your second table.
If you still have problems, post the part of the code that you are using and possibly it wud make me understand better, if I'm missing something now.

Regards,
Shravan:

Thanks for the help,sorry, I did substitute my field names. Here is the code below.

If I use the name of table (0) Employee or table (1) EmployeeRecords the loop to grab the child record does not happen. if I use the name of the datarelation "EmployeeGroup", the loop executes but returns a error

//Exception Details: System.ArgumentException: Column 'stat_Employee' does not belong to table Employee.

The column stat_employee does not exist in the table Employee, but EmployeeRecords, which it should determine from the data relation, shouldn't it?

Am I missing something ?

//******************************************************************
//
// MySession Class
//
// Used to represent a session along with its members and categories.
//
//******************************************************************
public class MySession
{
private SessionCollection _categories;

private UsersCollection_members;
private string_employeename;

private int_employeenumber;
public MySession()
{
}

public MySession(int RecordNumber)
{
_recordnumber = RecordNumber;
}

public MySession(

string EmployeeName,
int EmployeeNumber)
{

_employeename = EmployeeName;
_employeenumber = EmployeeNumber;
}

public UsersCollection Members
{
get{ return _members; }
set{ _members = value; }
}
public string EmployeeName
{
get{ return _employeename; }
set{ _employeename = value; }
}
public int EmployeeNumber
{
get{ return _employeenumber; }
set{ _employeenumber = value; }
}

//******************************************************************
//
// Retrieves a list of GridEntries
//
//******************************************************************
Public static SessionCollection GetEmployeeGridEntries( string SelDate)

{

DataSet ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[Web.Global.CfgKeyConnString],"SP_GetEmployeeWorkedGrid", Convert.ToDateTime(SelDate));

ds.Tables[0].TableName = "Employee";
ds.Tables[1].TableName = "EmployeeRecords";

DataColumn Parent;
DataColumn Child;

Parent =ds.Tables[0].Columns["Employee_Number"];
Child = ds.Tables[1].Columns["Stat_Employee"];

DataRelation dr = new DataRelation("EmployeeGroup", Parent,Child,false);
ds.Relations.Add(dr);

SessionCollection mysession = new SessionCollection();

foreach (DataRow r in ds.Tables[0].Rows)
{
MySession prj = new MySession();
prj.EmployeeName =r["EmployeeName"].ToString();

DataRow[] childr;
childr = r.GetChildRows("EmployeeRecords");
foreach (DataRow ChildRow in childr)
{
prj.EmployeeNumber = Convert.ToInt32(r["stat_Employee"]);

}
}

return mysession;

}
Bryan,
Your inner for loop seems to screw up the whole point here. r represents the rows of your parent table. Make the change as below to your inner loop.


foreach (DataRow ChildRow in childr)
{
prj.EmployeeNumber = Convert.ToInt32(ChildRow["stat_Employee"]);
}

hope that helps and do post what end result you got.

Regards,
Thanks Shravan:

Managed to get it to work (almost). The rows appear to be added to the collection, but the calling procedure

private void BindEmployeeGrid()
{
SessionCollection GridItems = BusinessLogicLayer.MySession.GetEmployeeGridEntries(txtCurrentDate.Text );
EmployeeGrid.DataSource = GridItems;
EmployeeGrid.DataBind();
}

throws an error when the grid is filled

"System.Web.HttpException: A field or property with the name 'EmployeeNumber' was not found on the selected datasource."

The field/property EmployeeNumber or EmployeeName is indeed part off the SessionCollection and appears to be filled when I debug.

Am I missing something in the setting up of the grid. ?
Bryan or Shravan,

Did you get this to work? ...and could you share how you did this with the Projects class in timetracker?

I have created a whole new application using TimeTracker as the framework. I came across Denis Bauer's HierarGrid yesterday and would like to implement it into my app.

I'm just not sure where to add the 'Relations' since the dataset is populated in the Project.vb and returned to the calling function as ProjectsCollection.

Regards
Hello Knute:

I too based my app on the timetracker framework. I could not figure out how to fill the Projects Collection from the dataset using a releation so I just filled it from the dataset (lack of experience I suppose <g>).

To be honest I think it's probably faster filling straight to a dataset as you don't have to loop through the dataset to add to the ProjectCollection. I never bothered using the project collection.

The Hierargrid is a nice tool, but I found it tends to be a bit slow to fill, I need to read up on optimizing my database for performance, I think this is where the bottlework maybe.

//Called from a web page

private void BindEmployeeGrid()
{
SessionCollection entryList = BusinessLogicLayer.MySession.GetEmployeeGridEntries(102,txtCurrentDate.Text );

DataSet GridItems;
GridItems = BusinessLogicLayer.MySession.GetEmployeeGridEntries(txtCurrentDate.Text );

EmployeeGrid.DataSource = GridItems;
EmployeeGrid.DataMember = "Employee";
EmployeeGrid.DataBind();
EmployeeGrid.RowExpanded[0] = true;
}

//the class
public static DataSet GetEmployeeGridEntries( string SelDate)
{

DataSet ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[Web.Global.CfgKeyConnString],"SP_GetEmployeeWorkedGrid", Convert.ToDateTime(SelDate));

ds.Tables[0].TableName = "Employee";
ds.Tables[1].TableName = "EmployeeRecords";

DataColumn Parent;
DataColumn Child;

//Relation
Parent =ds.Tables[0].Columns["Employee_Number"];
Child = ds.Tables[1].Columns["Stat_Employee"];
DataRelation dr = new DataRelation("EmployeeGroup", Parent,Child,false);
ds.Relations.Add(dr);
return ds;

}


Thanks Bryan:

I understand about bypassing the collection but is your stored procedure (SP_GetEmployeeWorkedGrid) basically...two SELECTs within the one stored procedure?

I've looked at Denis Bauer's TfsDemo and from the way the stored procedures are written I will have to change my approach to retrieving the data quite a bit.

About performance: (Just a thought)

We use ActiveDirectory on our network, however, when I set the following line in Webconfig to use "ActiveDirectory" the app slowed to a crawl - especially where Role=1. Try "None".

<add key="UserAccountSource" value="None" />
Knute:

Yes my stored procedure is TWO select statements with parameters for a date and a location (haven't implemented the location yet as this is why the parameter 102 is passed to the stored procedure in my example.

I will give your suggestions a try. i need to also look at caching as I am sure I can speed things up by implementing caching. Let me know how it works out. I struggled with the hierargrid for about 2 weeks brfore I got it working so I have goten pretty good at it<g
Thanks Bryan.

Great article in July 2004 issue of Access-VB-SQL Advisor on Caching:

Faster ASP.NET Applications
Use the ASP.NET Output Cache Engine to increase application performance.

By Stephen Forte, Technical Editor