superabbe
asked on
Replace comma to dot when SQL is loaded.
Hi Experts.
I use aspgrid from www.aspgrid.com
Object reference below:
http://www.aspgrid.com/objectreference.html
I will post the code below my explanation.
I have problems with commas and dots.
When I store a value using a dot in a field
in the aspgrid and then save the record is
turned into a comma.
Example:
12.1 become 12,1
The datatype for the table field is float.
The real proble is if I click on the edit button
and want to change a value in a record I must
cahnge all commas to dots again.
If I should ignore my validation code and store the value
in the form as 12,1 it turns to 121
Therefore I must use a dot before my decimals.
So the solution must be to display replace the commas to dots when pressing on the edit button.
I have tried several solutions but none fo them works.
Really need some expert help here.
THANKS IN ADVANCE.
-------------------------- ---------- ----------
<HTML>
<HEAD>
<TITLE>AspGrid 3.0 Demo - Expense Report</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function Validate()
{
if( isNaN(document.AspGridForm Save1.FIEL D5.value ) )
{
alert('Not a number.');
document.AspGridFormSave1. FIELD5.foc us();
return false;
}
if( isNaN(document.AspGridForm Save1.FIEL D6.value ) )
{
alert('Not a number.');
document.AspGridFormSave1. FIELD6.foc us();
return false;
}
if( isNaN(document.AspGridForm Save1.FIEL D7.value ) )
{
alert('Not a number.');
document.AspGridFormSave1. FIELD7.foc us();
return false;
}
if( isNaN(document.AspGridForm Save1.FIEL D8.value ) )
{
alert('Not a number.');
document.AspGridFormSave1. FIELD8.foc us();
return false;
}
if( document.AspGridFormSave1. FIELD5.val ue == "")
{
alert('Field is empty.');
document.AspGridFormSave1. FIELD5.foc us();
return false;
}
if( document.AspGridFormSave1. FIELD6.val ue == "")
{
alert('Field is empty.');
document.AspGridFormSave1. FIELD6.foc us();
return false;
}
if( document.AspGridFormSave1. FIELD7.val ue == "")
{
alert('Field is empty.');
document.AspGridFormSave1. FIELD7.foc us();
return false;
}
if( document.AspGridFormSave1. FIELD8.val ue == "")
{
alert('Field is empty.');
document.AspGridFormSave1. FIELD8.foc us();
return false;
}
return true;
}
</SCRIPT>
<body bgcolor="#FFFFFF">
<p><b>Op-register v0.0.1</b><br>
<%
' Create an instance of AspGrid
Set Grid = Server.CreateObject("Persi ts.Grid")
' Specify location of button images
Grid.Imagepath = "aspgrid/images/"
' Specify SQL statement. We store session IDs to allow simultaneos users to run the demo transparently
Grid.SQL = "select id, sessionid, Productid, OpLocationid, InternalTime, InternalYield, CustomerTime, CustomerYield, EditedDate from OpRegister WHERE Productid= '"&Cstr(session("sessProdu ctid"))&"' ORDER BY id"
' Connect using a DSNless connection string
ConnectStr = "Provider=SQLOLEDB;Server= madeleine; Database=O perationsr egister;UI D=sa;PWD="
Grid.Connect ConnectStr, "", ""
' Optional: specify a client-side JavaScript validation routine
Grid.FormOnSubmit = "return Validate();"
' Use POST rather than GET
Grid.MethodGet = False
' specify <TABLE> attributes of the grid
Grid.Table.CellSpacing = 0
Grid.Table.CellPadding = 0
Grid.Table.Width = 600
' Hide the ID and SESSIONID columns
Grid.ColRange(1, 3).Hidden = True
' specify the default value for the hidden SESSIONID column
Grid.Cols("sessionid").Def aultValue = Session.SessionID
Grid.Cols("Productid").Def aultValue = Cstr(session("sessProducti d"))
Response.write "Product:<font color=""red""><b>" & Cstr(session("sessProducti d")) & "</b></font><br>"
' Enable control buttons at both sides of grid
Grid.ShowLeftSideButtons
' Set header captions
Grid("OpLocationid").Capti on = "Location"
Grid("InternalTime").Capti on = "Tid1"
Grid("InternalYield").Capt ion = "Yield1"
Grid("CustomerTime").Capti on = "Tid2"
Grid("CustomerYield").Capt ion = "Yield2"
Grid("EditedDate").Caption = "Date"
' Set column width
Grid.Cols(0).Header.Width = 35
Grid.Cols(0).Cell.Width = 35
Grid.Cols(0).Cell.NoWrap = True
' Columns 1, 2 and 3 (id, sessionid and Productid) are hidden
Grid.Cols(4).Cell.Width = 10
Grid.Cols(4).Header.Width = 10
Grid.Cols(5).Cell.Width = 8
Grid.Cols(5).Header.Width = 8
Grid.Cols(6).Cell.Width = 10
Grid.Cols(6).Header.Width = 10
Grid.Cols(7).Cell.Width = 8
Grid.Cols(7).Header.Width = 8
Grid.Cols(8).Cell.Width = 10
Grid.Cols(8).Header.Width = 10
Grid.Cols(9).Cell.Width = 50
Grid.Cols(9).Header.Width = 50
Grid.Cols(999).Cell.Width = 35
Grid.Cols(999).Header.Widt h = 35
Grid.Cols(999).Cell.NoWrap = True
' Set fonts, colors for the control columns
Grid.Cols(0).Header.BgColo r = "#90F0FE"
Grid.Cols(0).Cell.Align = "CENTER"
Grid.Cols(0).Cell.BgColor = "#FFFFFF"
Grid.Cols(0).Cell.AltBgCol or = "#E0E0E0"
Grid.Cols(0).Footer.Align = "CENTER"
Grid.Cols(999).Header.BgCo lor = "#90F0FE"
Grid.Cols(999).Cell.Align = "CENTER"
Grid.Cols(999).Cell.BgColo r = "#FFFFFF"
Grid.Cols(999).Cell.AltBgC olor = "#E0E0E0"
Grid.Cols(999).Footer.Alig n = "CENTER"
' Set fonts, colors and sizes for the data columns
Grid.ColRange(2, 9).Header.Font.Face = "Arial"
Grid.ColRange(2, 9).Header.Font.Size = 2
Grid.ColRange(2, 9).Header.BgColor = "#A6CAF0"
Grid.ColRange(2, 9).Header.NoWrap = True
Grid.ColRange(2, 9).Cell.Font.Face = "Arial"
Grid.ColRange(2, 9).Cell.Font.Size = 2
Grid.ColRange(2, 9).Cell.BgColor = "#FFFFFF"
Grid.ColRange(2, 9).Cell.AltBgColor = "#E0E0E0"
' Grid.Cols(<index>) is equivalent to Grid(<index>) as Cols is the default property
' Set the SIZE attribute for <INPUT TYPE=TEXT> '
Grid("OpLocationid").Input Size = 6
Grid("InternalTime").Input Size = 6
Grid("InternalYield").Inpu tSize = 6
Grid("CustomerTime").Input Size = 6
Grid("CustomerYield").Inpu tSize = 6
Grid("EditedDate").InputSi ze = 10
' Display Category field as a drop-down list
Grid("OpLocationid").Attac hForeignTa ble "select OpLocationId, OpLocationName from OpLocation Where QuerySelection='"&Cstr(ses sion("sess Scheme"))& "' ", 1, 2
' Format the Date column
Grid("EditedDate").FormatD ate "%d %b %Y", "%d %b %Y"
Grid("EditedDate").Default Value = Date
Grid("EditedDate").AttachC alendar
Grid("EditedDate").Cell.No Wrap = True
' Enable sorting on all visible fields
Grid.ColRange(2, 9).CanSort = True
' Enable client-side confirmation on record deletion
Grid.DeleteButtonOnClick = "Are you sure you want to delete this record? (This message is cusomizable)"
Grid.FormOnSubmit = "return Validate();"
' Peform server-side validation of date
If Request("AspGridSave1.x") <> "" Then ' Adding or saving in progress
If Not IsDate(Request("FIELD9")) Then
Response.Write "<B><FONT SIZE=2 FACE=Arial COLOR=#FF0000>Server-side validation: this is not a date!</FONT></B><P>"
Grid.IgnoreCommands ' do not save!
Else ' verify date range
TheDate = CDate(Request("FIELD9"))
If TheDate < CDate("1/1/1995") Then
Response.Write "<B><FONT SIZE=2 FACE=Arial COLOR=#FF0000>Server-side validation: A date must be after 1/1/1995!</FONT></B><P>"
Grid.IgnoreCommands ' do not save!
End If
End If
End If
Grid.Display
' Display a total by requerying the same recordset
Response.Write "<P>"
Set Rec = grid.Recordset
Rec.Requery
InternalTime = 0
InternalYield = 0
CustomerTime=0
CustomerYield=0
while Not Rec.EOF
InternalTime = InternalTime + Rec("InternalTime")
InternalYield = InternalYield + Rec("InternalYield")
CustomerTime = CustomerTime + Rec("CustomerTime")
CustomerYield = CustomerYield + Rec("CustomerYield")
Rec.MoveNext
wend
Response.Write "<FONT SIZE=3><B>Internal time: " & InternalTime & "</B></FONT><br>"
Response.Write "<FONT SIZE=3><B>Internal yield: " & InternalYield & "</B></FONT><br>"
Response.Write "<FONT SIZE=3><B>Customer time: " & CustomerTime & "</B></FONT><br>"
Response.Write "<FONT SIZE=3><B>Customer yield: " & CustomerYield & "</B></FONT>"
Set Grid = Nothing
%>
</p>
</BODY>
</HTML>
I use aspgrid from www.aspgrid.com
Object reference below:
http://www.aspgrid.com/objectreference.html
I will post the code below my explanation.
I have problems with commas and dots.
When I store a value using a dot in a field
in the aspgrid and then save the record is
turned into a comma.
Example:
12.1 become 12,1
The datatype for the table field is float.
The real proble is if I click on the edit button
and want to change a value in a record I must
cahnge all commas to dots again.
If I should ignore my validation code and store the value
in the form as 12,1 it turns to 121
Therefore I must use a dot before my decimals.
So the solution must be to display replace the commas to dots when pressing on the edit button.
I have tried several solutions but none fo them works.
Really need some expert help here.
THANKS IN ADVANCE.
--------------------------
<HTML>
<HEAD>
<TITLE>AspGrid 3.0 Demo - Expense Report</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function Validate()
{
if( isNaN(document.AspGridForm
{
alert('Not a number.');
document.AspGridFormSave1.
return false;
}
if( isNaN(document.AspGridForm
{
alert('Not a number.');
document.AspGridFormSave1.
return false;
}
if( isNaN(document.AspGridForm
{
alert('Not a number.');
document.AspGridFormSave1.
return false;
}
if( isNaN(document.AspGridForm
{
alert('Not a number.');
document.AspGridFormSave1.
return false;
}
if( document.AspGridFormSave1.
{
alert('Field is empty.');
document.AspGridFormSave1.
return false;
}
if( document.AspGridFormSave1.
{
alert('Field is empty.');
document.AspGridFormSave1.
return false;
}
if( document.AspGridFormSave1.
{
alert('Field is empty.');
document.AspGridFormSave1.
return false;
}
if( document.AspGridFormSave1.
{
alert('Field is empty.');
document.AspGridFormSave1.
return false;
}
return true;
}
</SCRIPT>
<body bgcolor="#FFFFFF">
<p><b>Op-register v0.0.1</b><br>
<%
' Create an instance of AspGrid
Set Grid = Server.CreateObject("Persi
' Specify location of button images
Grid.Imagepath = "aspgrid/images/"
' Specify SQL statement. We store session IDs to allow simultaneos users to run the demo transparently
Grid.SQL = "select id, sessionid, Productid, OpLocationid, InternalTime, InternalYield, CustomerTime, CustomerYield, EditedDate from OpRegister WHERE Productid= '"&Cstr(session("sessProdu
' Connect using a DSNless connection string
ConnectStr = "Provider=SQLOLEDB;Server=
Grid.Connect ConnectStr, "", ""
' Optional: specify a client-side JavaScript validation routine
Grid.FormOnSubmit = "return Validate();"
' Use POST rather than GET
Grid.MethodGet = False
' specify <TABLE> attributes of the grid
Grid.Table.CellSpacing = 0
Grid.Table.CellPadding = 0
Grid.Table.Width = 600
' Hide the ID and SESSIONID columns
Grid.ColRange(1, 3).Hidden = True
' specify the default value for the hidden SESSIONID column
Grid.Cols("sessionid").Def
Grid.Cols("Productid").Def
Response.write "Product:<font color=""red""><b>" & Cstr(session("sessProducti
' Enable control buttons at both sides of grid
Grid.ShowLeftSideButtons
' Set header captions
Grid("OpLocationid").Capti
Grid("InternalTime").Capti
Grid("InternalYield").Capt
Grid("CustomerTime").Capti
Grid("CustomerYield").Capt
Grid("EditedDate").Caption
' Set column width
Grid.Cols(0).Header.Width = 35
Grid.Cols(0).Cell.Width = 35
Grid.Cols(0).Cell.NoWrap = True
' Columns 1, 2 and 3 (id, sessionid and Productid) are hidden
Grid.Cols(4).Cell.Width = 10
Grid.Cols(4).Header.Width = 10
Grid.Cols(5).Cell.Width = 8
Grid.Cols(5).Header.Width = 8
Grid.Cols(6).Cell.Width = 10
Grid.Cols(6).Header.Width = 10
Grid.Cols(7).Cell.Width = 8
Grid.Cols(7).Header.Width = 8
Grid.Cols(8).Cell.Width = 10
Grid.Cols(8).Header.Width = 10
Grid.Cols(9).Cell.Width = 50
Grid.Cols(9).Header.Width = 50
Grid.Cols(999).Cell.Width = 35
Grid.Cols(999).Header.Widt
Grid.Cols(999).Cell.NoWrap
' Set fonts, colors for the control columns
Grid.Cols(0).Header.BgColo
Grid.Cols(0).Cell.Align = "CENTER"
Grid.Cols(0).Cell.BgColor = "#FFFFFF"
Grid.Cols(0).Cell.AltBgCol
Grid.Cols(0).Footer.Align = "CENTER"
Grid.Cols(999).Header.BgCo
Grid.Cols(999).Cell.Align = "CENTER"
Grid.Cols(999).Cell.BgColo
Grid.Cols(999).Cell.AltBgC
Grid.Cols(999).Footer.Alig
' Set fonts, colors and sizes for the data columns
Grid.ColRange(2, 9).Header.Font.Face = "Arial"
Grid.ColRange(2, 9).Header.Font.Size = 2
Grid.ColRange(2, 9).Header.BgColor = "#A6CAF0"
Grid.ColRange(2, 9).Header.NoWrap = True
Grid.ColRange(2, 9).Cell.Font.Face = "Arial"
Grid.ColRange(2, 9).Cell.Font.Size = 2
Grid.ColRange(2, 9).Cell.BgColor = "#FFFFFF"
Grid.ColRange(2, 9).Cell.AltBgColor = "#E0E0E0"
' Grid.Cols(<index>) is equivalent to Grid(<index>) as Cols is the default property
' Set the SIZE attribute for <INPUT TYPE=TEXT> '
Grid("OpLocationid").Input
Grid("InternalTime").Input
Grid("InternalYield").Inpu
Grid("CustomerTime").Input
Grid("CustomerYield").Inpu
Grid("EditedDate").InputSi
' Display Category field as a drop-down list
Grid("OpLocationid").Attac
' Format the Date column
Grid("EditedDate").FormatD
Grid("EditedDate").Default
Grid("EditedDate").AttachC
Grid("EditedDate").Cell.No
' Enable sorting on all visible fields
Grid.ColRange(2, 9).CanSort = True
' Enable client-side confirmation on record deletion
Grid.DeleteButtonOnClick = "Are you sure you want to delete this record? (This message is cusomizable)"
Grid.FormOnSubmit = "return Validate();"
' Peform server-side validation of date
If Request("AspGridSave1.x") <> "" Then ' Adding or saving in progress
If Not IsDate(Request("FIELD9")) Then
Response.Write "<B><FONT SIZE=2 FACE=Arial COLOR=#FF0000>Server-side validation: this is not a date!</FONT></B><P>"
Grid.IgnoreCommands ' do not save!
Else ' verify date range
TheDate = CDate(Request("FIELD9"))
If TheDate < CDate("1/1/1995") Then
Response.Write "<B><FONT SIZE=2 FACE=Arial COLOR=#FF0000>Server-side validation: A date must be after 1/1/1995!</FONT></B><P>"
Grid.IgnoreCommands ' do not save!
End If
End If
End If
Grid.Display
' Display a total by requerying the same recordset
Response.Write "<P>"
Set Rec = grid.Recordset
Rec.Requery
InternalTime = 0
InternalYield = 0
CustomerTime=0
CustomerYield=0
while Not Rec.EOF
InternalTime = InternalTime + Rec("InternalTime")
InternalYield = InternalYield + Rec("InternalYield")
CustomerTime = CustomerTime + Rec("CustomerTime")
CustomerYield = CustomerYield + Rec("CustomerYield")
Rec.MoveNext
wend
Response.Write "<FONT SIZE=3><B>Internal time: " & InternalTime & "</B></FONT><br>"
Response.Write "<FONT SIZE=3><B>Internal yield: " & InternalYield & "</B></FONT><br>"
Response.Write "<FONT SIZE=3><B>Customer time: " & CustomerTime & "</B></FONT><br>"
Response.Write "<FONT SIZE=3><B>Customer yield: " & CustomerYield & "</B></FONT>"
Set Grid = Nothing
%>
</p>
</BODY>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
but here's some code to change commas into dots
strVar = Replace(strVar,",",".")
so it'd probably be something like this
strVar = RSobj(FieldName)
strVar = Replace(strVar,",",".")
Response.Write strVar