Saturday, March 31, 2012
String to equation
I have a field in SQL server that is set as a varchar but contains data like
>50 or <2 which is actually a target percentage. I have data in another
table stored as Decimal(14,2) that is the actual percentage. I need to
extract the two and create a conditional formatting result in a datalist.
Basically it would be something like this.
Assume actualpercentage = 30
targetpercentage = >50
If actual percentagetargetpercentage = True then forecolor= "Green"
Else
forecolor = "Red"
In actual terms it would be like
If 30>50 = True then forecolor = "Green"
Else
forecolor = "Red"
Don't worry about setting the color I can get that accomplished if I could
just build the boolean expression. And trust me I know the way it is written
here seems weird but it represents what I need to test. Basically the target
percentage is anything above 50% so I need to test and see if the actual was
greater than the target. However, like I show before the target could be
anything like <2%
Thanks for any help, a function or any mechanism for that matter would be
great.
Marty UHi Mary,
Obviously the first thing to do is to parse your varchar field. You stated
that your column "contains data like >50 or <2" - you need to get more
specific than that, becuase in essence, you have stored 2 different things
in the column, and the first thing you need is to split your string into 2
pieces. The only way to do that is to know what all of the possible values
for the first (comparison operator) is, so that you can identify where
tosplit the data. Of course, this would have been much easier if you had
used 2 columns to store the 2 values; that is good database design. But once
you've identified all the possible values of the first part, you can create
a loop that loops through all of them and uses the index of the last
character to determine where to split the value. Once split into 2 values,
you need to create a loop which selects from various kinds of comparison
operators that correspond to the ones in your list of possibles, and builds
a comparison statement from one of them.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Marty Underwood" <martman100@.insightbb.com> wrote in message
news:bczYb.341294$xy6.1700666@.attbi_s02...
> Got a quick question that I cannot get to work at work!
> I have a field in SQL server that is set as a varchar but contains data
like
> >50 or <2 which is actually a target percentage. I have data in another
> table stored as Decimal(14,2) that is the actual percentage. I need to
> extract the two and create a conditional formatting result in a datalist.
> Basically it would be something like this.
> Assume actualpercentage = 30
> targetpercentage = >50
> If actual percentagetargetpercentage = True then forecolor= "Green"
> Else
> forecolor = "Red"
> In actual terms it would be like
> If 30>50 = True then forecolor = "Green"
> Else
> forecolor = "Red"
>
> Don't worry about setting the color I can get that accomplished if I could
> just build the boolean expression. And trust me I know the way it is
written
> here seems weird but it represents what I need to test. Basically the
target
> percentage is anything above 50% so I need to test and see if the actual
was
> greater than the target. However, like I show before the target could be
> anything like <2%
> Thanks for any help, a function or any mechanism for that matter would be
> great.
> Marty U
>
Hi Marty,
Look at the String.Substring() method. It's overloaded. One version takes
one parameter, which is the starting index of the substring. It reads to the
end of the string. The other takes a second parameter which is the number of
characters to get. So, assuming that your data, as you said, has only 2
single-character comparison operators, you can get the 2 values from it by
using the String.Substring method(). Example:
Dim s As String = "<123"
Dim operator As String = s.Substring(0, 1)
Dim value As Integer = Convert.ToInt32(s.Substring(1))
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Marty U" <anonymous@.discussions.microsoft.com> wrote in message
news:8ABD3BD8-4FD3-456D-8DA0-722D75DCD452@.microsoft.com...
> Thanks for the reply Kevin,
> The only two comparison operators would be the greater than, less than
operators. I would have split these into two different columns but the
customer never said they would be used for actual comparisons but just a
display mechanism. Now I don't have time to redesign the related objects
that would use the split column.
> I had an idea of creating a function that receives 3 items.
> Function ShowResult(ActualValue as Decimal, theOperator as String,
TargetValue as Decimal)
> Dim theResult as Boolean
> theResult = ActualValuetheOperatorTargetValue
> Select Case theResult
> Case "True"
> do something
> Case "False"
> do something
> End Select
> End Function
> I would use a Left(TargetValue, 1) to pass theOperator argument. Can you
look at this theory and give me an idea how I can pass these 3 items into a
function and get the desired result of whether it's true or false.
> Thanks again, I don't have time to harp on this since I have a deadline of
Friday and this is just a perk they would like to have.
Sounds good I will look into this tomorrow at work. Oh and by the way I did
split the column into two seperate columns today due to another issue I had
that was not worth the trouble. It was easier to modify six pages of code
and modify the database then to program with the data being combined in the
DB.
Marty U
"Kevin Spencer" <kevin@.takempis.com> wrote in message
news:e2rCPxk9DHA.452@.TK2MSFTNGP11.phx.gbl...
> Hi Marty,
> Look at the String.Substring() method. It's overloaded. One version takes
> one parameter, which is the starting index of the substring. It reads to
the
> end of the string. The other takes a second parameter which is the number
of
> characters to get. So, assuming that your data, as you said, has only 2
> single-character comparison operators, you can get the 2 values from it by
> using the String.Substring method(). Example:
> Dim s As String = "<123"
> Dim operator As String = s.Substring(0, 1)
> Dim value As Integer = Convert.ToInt32(s.Substring(1))
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "Marty U" <anonymous@.discussions.microsoft.com> wrote in message
> news:8ABD3BD8-4FD3-456D-8DA0-722D75DCD452@.microsoft.com...
> > Thanks for the reply Kevin,
> > The only two comparison operators would be the greater than, less than
> operators. I would have split these into two different columns but the
> customer never said they would be used for actual comparisons but just a
> display mechanism. Now I don't have time to redesign the related objects
> that would use the split column.
> > I had an idea of creating a function that receives 3 items.
> > Function ShowResult(ActualValue as Decimal, theOperator as String,
> TargetValue as Decimal)
> > Dim theResult as Boolean
> > theResult = ActualValuetheOperatorTargetValue
> > Select Case theResult
> > Case "True"
> > do something
> > Case "False"
> > do something
> > End Select
> > End Function
> > I would use a Left(TargetValue, 1) to pass theOperator argument. Can you
> look at this theory and give me an idea how I can pass these 3 items into
a
> function and get the desired result of whether it's true or false.
> > Thanks again, I don't have time to harp on this since I have a deadline
of
> Friday and this is just a perk they would like to have.
string to string[]
I've got this code :
string[] Params;string SQL = "SELECT * FROM T_MANAGEMENT_PAGES";
SqlCommand myCommand = new SqlCommand(SQL, myConnection);
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();try
{
while (myReader.Read())
{
Params_Type = myReader.GetValue(0).ToString();
}
}
catch
{
}
finally
{
}
myReader.Close();
My problem is to obtain Params_Type.
But each time, it says : "impossible to convert '[object]' in 'string[]' "
Thanks for all.
SébHello, try this instead:
int i = 0;
while (myReader.Read())
{
Params_Type[i] = myReader.GetValue(0).ToString();
i++;
}
Hope this works fine for u.
Yes but, in my database I have in one column :
{"BURE_ETUD_ID","LANG_ID","LANG_NAME"}
My sql return only one line.
and what I want is :
string[] Params = {"BURE_ETUD_ID","LANG_ID","LANG_NAME"};
Thanks
Séb
You should, ideally, rework your database. This is not a great layout. You should have a table that links to this record and has one row per entry to allow you to better get at the data.
Given the string returned as it is, you could use String.Split() to create a string array.
I Agree with you, but is there any possibility to convert one string in one string[] ?
Séb
Yes. As I mentioned in my last post: the String class has a Split() method. Please look at the docs.
I'm sorry, i haven't see the end of your message.
Thanks for your heulp
Regards
Séb
Hello,
I believe yes, you should rework ur database, each value should be in one column. this is typical !!!
then, after u rework ur database, use the code i gave, it works just fine.
Good Luck.
Wednesday, March 28, 2012
String was not recognized as a valid DateTime Error
"String was not recognized as a valid DateTime"
Here is my code:
private string dateFormatting(String theDate)
{
DateTime strDate;
strDate = Convert.ToDateTime(theDate);
strDate = strDate.ToString("M");
return strDate;
}
theDate has the value of "5/11/2005 5:10:25 PM". If I copy-and-paste the string into the code (instead of "theDate"), it compiles properly. However, leaving it in a variable always return the error above.
What might cause this problem?
Thanks
I'm having the same trouble... Can it be a bug?
Regards,
Luis Sim?es
Your variable "strDate" is a DateTime type. You are trying to fill a DateTime variable with a string:
strDate = strDate.ToString("M");
try this:
privatestring dateFormatting(string theDate)
{
DateTime strDate;
strDate = DateTime.Parse(theDate);
string stringDate = strDate.ToString("M");
return stringDate;
}
this may sound like a dumb question, but are you absoulutly sure that the date you paste in is the same date that your code is reciveing, as in have you place a breakpoint in and checked this for sure. One possibility is that the source of your date string has a different culture to the server running the convert.
On a side note, if your function only formats a date then why not only have yout functon accept a date rather then a string? In other words what context is this function performing its role of the conversion, is it from a databind or from a database object?
I'm not sure if it's gonna change anything but.. try to convert like this..
Convert.ToShortDateTime(variable);
anyway... I guess it changes nothing... except that the date will be returned different..
I am not sure if it's gonna change anything.. but.. try to use like this:
Convert.ToShortDateTime(var_name);
I don't know if it will make any difference at all.. I think it wont accutally... I mean.. about this error...
andrew_K wrote:
this may sound like a dumb question, but are you absoulutly sure that the date you paste in is the same date that your code is reciveing, as in have you place a breakpoint in and checked this for sure. One possibility is that the source of your date string has a different culture to the server running the convert.
On a side note, if your function only formats a date then why not only have yout functon accept a date rather then a string? In other words what context is this function performing its role of the conversion, is it from a databind or from a database object?
I am positive that the date I pasted is the same as the date that my code is receiving.
I have the function accept a string because it is called from a databind. I have tried converting the date before passing it to the function, and it returns the same error. I'd post the code, but I am at home now *-)
DevSlick wrote:
Your variable "strDate" is a DateTime type. You are trying to fill a DateTime variable with a string:
strDate = strDate.ToString("M");
try this:privatestring dateFormatting(string theDate)
{
DateTime strDate;
strDate = DateTime.Parse(theDate);
string stringDate = strDate.ToString("M");
return stringDate;
}
It still returned the same error onstrDate = DateTime.Parse(theDate);
This is very weird.
Weird, it worked for me
This is driving me crazy. Here's the entire code. Maybe the problem is somewhere else. The stored procedure returns two values, the date and an id. Any help would be greatly appreciated!
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource dsAdmin = new SqlDataSource();
dsAdmin.ConnectionString = "Data Source=(local);Initial Catalog=birdhair;Integrated Security=True";
dsAdmin.SelectCommand = "usp_Admin_ArchiveList";
dsAdmin.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
Parameter sParam1 = new Parameter();
sParam1.Name = "month";
sParam1.Type = TypeCode.Int32;
sParam1.DefaultValue = DateTime.Now.Month.ToString();
dsAdmin.SelectParameters.Add(sParam1);
Parameter sParam2 = new Parameter();
sParam2.Name = "Year";
sParam2.Type = TypeCode.Int32;
sParam2.DefaultValue = DateTime.Now.Year.ToString();
dsAdmin.SelectParameters.Add(sParam2);
DataGrid gridYear = new DataGrid();
gridYear.AutoGenerateColumns = false;
gridYear.DataSource = dsAdmin;
placeholder.Controls.Add(gridYear);
HyperLinkColumn column = new HyperLinkColumn();
column.DataNavigateUrlField = "LogID";
column.DataNavigateUrlFormatString = "edit.aspx?LogID={0}";
column.DataTextField = "LogTimeStamp";
column.DataTextFormatString = dateFormatting("{0}");
gridYear.Columns.Add(column);
gridYear.DataBind();
}
private string dateFormatting(String theDate)
{
DateTime strDate;
String stringDate;
strDate = DateTime.Parse(theDate);
stringDate = strDate.ToString("M");
return stringDate;
}
String was not recognized as a valid DateTime.
works and I get the EditCommand to work. When I make a change to a
field, I get a date error. I was getting invalid cast error, but I
changed my Update script. All the scripts I found seem to work up to
that point. What am I missing? BTW-Im using c#.
Here is my Update Script, nor the datetime cast within the parameter
assignment:
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//--retrieve textbox controls from datagrid--//
string iID = e.Item.Cells[1].Text;
string dtDate = e.Item.Cells[3].Text;
string strMeal = e.Item.Cells[4].Text;
string strLodge = e.Item.Cells[5].Text;
//--assign parameters--//
this.sqlCommand1.Parameters.Add("@dotnet.itags.org.TripDate",Convert.ToDateTime(dtDate.ToString()));
this.sqlCommand1.Parameters["@dotnet.itags.org.Param1"].Value = strMeal.ToString();
this.sqlCommand1.Parameters["@dotnet.itags.org.Param2"].Value = strLodge.ToString();
this.sqlCommand1.Parameters["@dotnet.itags.org.id"].Value = iID;
//--execute update query script--//
// this.sqlConnection1.Open();
// this.sqlCommand1.ExecuteNonQuery();
//--deselect row for edting--//
this.DataGrid1.EditItemIndex = -1;
this.DataGrid1.ShowFooter = true;
BindGrid();
//--debugging code--//
Response.Write(Convert.ToDateTime(dtDate.ToString( )));
}
--
hodgesp
----------------------
Posted via http://www.codecomments.com
----------------------Hi hodgesp,
If after you click Edit button, some field become textboxe, in
datagrid_UpdateCommand event, you should get the textbox first. Then retrieve
data:
TextBox txtDtDate = e.Item.Cells[3].Controls[0] as TextBox;
string dtDate = txtDtDate.Text;
HTH
Elton Wang
"hodgesp" wrote:
> I have a Datagrid that I'm trying to use to update a SQL table. The grid
> works and I get the EditCommand to work. When I make a change to a
> field, I get a date error. I was getting invalid cast error, but I
> changed my Update script. All the scripts I found seem to work up to
> that point. What am I missing? BTW-Im using c#.
> Here is my Update Script, nor the datetime cast within the parameter
> assignment:
>
> private void DataGrid1_UpdateCommand(object source,
> System.Web.UI.WebControls.DataGridCommandEventArgs e)
> {
>
> //--retrieve textbox controls from datagrid--//
> string iID = e.Item.Cells[1].Text;
> string dtDate = e.Item.Cells[3].Text;
> string strMeal = e.Item.Cells[4].Text;
> string strLodge = e.Item.Cells[5].Text;
>
> //--assign parameters--//
> this.sqlCommand1.Parameters.Add("@.TripDate",Convert.ToDateTime(dtDate.ToString()));
>
> this.sqlCommand1.Parameters["@.Param1"].Value = strMeal.ToString();
> this.sqlCommand1.Parameters["@.Param2"].Value = strLodge.ToString();
> this.sqlCommand1.Parameters["@.id"].Value = iID;
>
> //--execute update query script--//
> // this.sqlConnection1.Open();
> // this.sqlCommand1.ExecuteNonQuery();
>
> //--deselect row for edting--//
> this.DataGrid1.EditItemIndex = -1;
> this.DataGrid1.ShowFooter = true;
> BindGrid();
>
> //--debugging code--//
> Response.Write(Convert.ToDateTime(dtDate.ToString( )));
> }
>
> --
> hodgesp
> ----------------------
> Posted via http://www.codecomments.com
> ----------------------
>
String was not recognized as a valid DateTime.
ks and I get the EditCommand to work. When I make a change to a field, I ge
t a date error. I was getting invalid cast error, but I changed my Update sc
ript. All the scripts I found seem to work up to that point. What am I missi
ng? BTW-Im using c#.
Here is my Update Script, nor the datetime cast within the parameter assignm
ent:
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControl
s.DataGridCommandEventArgs e)
{
//--retrieve textbox controls from datagrid--//
string iID = e.Item.Cells[1].Text;
string dtDate = e.Item.Cells[3].Text;
string strMeal = e.Item.Cells[4].Text;
string strLodge = e.Item.Cells[5].Text;
//--assign parameters--//
this.sqlCommand1.Parameters.Add("@dotnet.itags.org.TripDate",Convert.ToDateTime(dtDate.ToStri
ng()));
this.sqlCommand1.Parameters["@dotnet.itags.org.Param1"].Value = strMeal.ToString();
this.sqlCommand1.Parameters["@dotnet.itags.org.Param2"].Value = strLodge.ToString();
this.sqlCommand1.Parameters["@dotnet.itags.org.id"].Value = iID;
//--execute update query script--//
// this.sqlConnection1.Open();
// this.sqlCommand1.ExecuteNonQuery();
//--deselect row for edting--//
this.DataGrid1.EditItemIndex = -1;
this.DataGrid1.ShowFooter = true;
BindGrid();
//--debugging code--//
Response.Write(Convert.ToDateTime(dtDate.ToString()));
}Hi hodgesp,
If after you click Edit button, some field become textboxe, in
datagrid_UpdateCommand event, you should get the textbox first. Then retriev
e
data:
TextBox txtDtDate = e.Item.Cells[3].Controls[0] as TextBox;
string dtDate = txtDtDate.Text;
HTH
Elton Wang
"hodgesp" wrote:
> I have a Datagrid that I'm trying to use to update a SQL table. The grid
> works and I get the EditCommand to work. When I make a change to a
> field, I get a date error. I was getting invalid cast error, but I
> changed my Update script. All the scripts I found seem to work up to
> that point. What am I missing? BTW-Im using c#.
> Here is my Update Script, nor the datetime cast within the parameter
> assignment:
>
> private void DataGrid1_UpdateCommand(object source,
> System.Web.UI.WebControls.DataGridCommandEventArgs e)
> {
>
> //--retrieve textbox controls from datagrid--//
> string iID = e.Item.Cells[1].Text;
> string dtDate = e.Item.Cells[3].Text;
> string strMeal = e.Item.Cells[4].Text;
> string strLodge = e.Item.Cells[5].Text;
>
> //--assign parameters--//
> this.sqlCommand1.Parameters.Add("@.TripDate",Convert.ToDateTime(dtDate.ToSt
ring()));
>
> this.sqlCommand1.Parameters["@.Param1"].Value = strMeal.ToString();
> this.sqlCommand1.Parameters["@.Param2"].Value = strLodge.ToString();
> this.sqlCommand1.Parameters["@.id"].Value = iID;
>
> //--execute update query script--//
> // this.sqlConnection1.Open();
> // this.sqlCommand1.ExecuteNonQuery();
>
> //--deselect row for edting--//
> this.DataGrid1.EditItemIndex = -1;
> this.DataGrid1.ShowFooter = true;
> BindGrid();
>
> //--debugging code--//
> Response.Write(Convert.ToDateTime(dtDate.ToString()));
> }
>
> --
> hodgesp
> ---
> Posted via http://www.codecomments.com
> ---
>
Monday, March 26, 2012
StringBuilder and memory management
iterations, I write the SQL to the database, and use the
StringBuilder.Remove method to "zero out" the string: e.g.,
"oStringBuilder.Remove(0,oStringBuilder.Length)". I then reuse
oStringBuilder to build the next SQL statement.
Sometimes this coding works fine, but as often as not the system reports
an out-of-memory error. I'm guessing that the Remove method deletes the
text in a string, but does not remove its memory allocation, and when I
reuse it, the string grows ever larger.
Is there any mechanism to destroy memory used -- or shrink it to zero
(or something!) -- within the StringBuilder class? If not, any other ideas?
Many thanks.
-- Brent
//==================================================
//Code snippet builds a valid MySQL statement
sqlstart = "Insert into myTable (Field1, Field2) Values ";
string field;
int count = 1;
StringBuilder sql = new StringBuilder(sqlstart);
char[] fieldsplitter = {'|'};
//after getting an array of text rows
for(int i = 0; i < arrRows.Length; i++, count++)
{
string[] arrFields = arrRows[i].Split(fieldsplitter);
sql.Append("(");
for(int j=0; j < arrFields.Length; j++)
{
field = arrFields[j];
sql.Append("'"+field+"',");
}
if (count==100 | i == arrRows.Length - 2)
{
sql.Append(");");
try
{
//write SQL to DB using "run" class
run.exec(sql.ToString());
}
catch //error in sql
{
Response.Write("SQL error: " + sql);
}
count = 0;
sql.Remove(0,sql.Length);
sql.Append(sqlstart);
}
else{sql.Append("),");}
}
//===============================================why not just reinstantiate the object? i don't know how the
stringbuilder class keeps references to its data, so it might not be
killing all references to it (keeping gc from happening).
reinitializing the stringbuilder ought to fix it if it's causing the
problem.
if that doesn't fix it, i'd suggest running a profiler on your
application to see where memory is getting sucked out.
hth
terry
Thanks for the tip. Turns out that I was reading in very large strings
from a file, and the memory was eaten up by that portion of the code,
not the code I posted earlier.
Thanks for your help!
theath wrote:
> why not just reinstantiate the object? i don't know how the
> stringbuilder class keeps references to its data, so it might not be
> killing all references to it (keeping gc from happening).
> reinitializing the stringbuilder ought to fix it if it's causing the
> problem.
> if that doesn't fix it, i'd suggest running a profiler on your
> application to see where memory is getting sucked out.
> hth
> terry
strings in db question.
store the string in my sql database.
I noticed that I get an error when someone enters a string with a ' in it.
I'm going to test for that, and possibly make a special case to handle that
character.
are there any other characters that i need to watch out for?Depending upon the settings, you might need to guard against " (quote) as well.
The better solution is to use parameters.This article shows you how.
Tuesday, March 13, 2012
stuck and confused
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
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 and confused
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...
>