Answered by:
datatable, datacolumn Visual Studio 2005 Beta 2

Question
-
This code fails at the codeline '.expression = "IIf .......'
This code works properly with Visual Studio 2003.
The tool used is Visual Studio 2005 Beta 2. If it is a bug is there a patch
or a work around if not what is wrong with these lines.
thanks
Gerhard.
Private Sub CalcColumns() Dim rate As Single = 0.0862 Dim table As DataTable = New DataTable("MyTable") ' Create the first column. Dim priceColumn As DataColumn = New DataColumn With priceColumn.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "price"
.DefaultValue = 50
End With ' Create the second, calculated, column. Dim taxColumn As DataColumn = New DataColumn With taxColumn.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "tax"
.Expression = "price * 0,0862"
End With ' Create third column Dim totalColumn As DataColumn = New DataColumn With totalColumn.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "total"
.Expression = "IIf(price > 0, price * tax, tax)"
End With ' Add columns to DataTable With table.Columns.Add(priceColumn)
.Add(taxColumn)
.Add(totalColumn)
End With Dim row As DataRow = table.NewRowtable.Rows.Add(row)
Dim view As New DataViewview.Table = table
DataGrid1.DataSource = view
System.Data.SyntaxErrorException was unhandled
Message="Syntax error: Missing operand after 'price' operator."
Source="System.Data"
StackTrace:
at System.Data.ExpressionParser.Parse()at System.Data.DataExpression..ctor(DataTable table, String expression, Type type)
at System.Data.DataColumn.set_Expression(String value)
at TestExpressionSQL2005.Form1.CalcColumns() in D:\ProgEnt\Visual Studio\projects\vb\TestExpressionSQL2005\TestExpressionSQL2005\Form1.vb:line 30
at TestExpressionSQL2005.Form1.Button1_Click(Object sender, EventArgs e) in D:\ProgEnt\Visual Studio\projects\vb\TestExpressionSQL2005\TestExpressionSQL2005\Form1.vb:line 49
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at TestExpressionSQL2005.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 76
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Wednesday, November 16, 2005 6:12 AM
Answers
-
not really; I added one space more.
"IIf(pric > 0 , price * tax , tax)"
buuuuuut
yesterday I installed the latest Version of Visual Studio 2005
Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727
Installed Edition: Professional
and the latest version of MS SQL server 2005( 9.0.1399)
Result :
The problems seem to be fixed. The behaviour is as it was in VS 2003.
Thursday, November 17, 2005 5:42 AM
All replies
-
Do you have a type in
With taxColumn
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "tax"
.Expression = "price * 0,0862"
End With
Should 0,0862 be 0.0862?
I do not see a problem after correct this.
Could you confirm first if this is the problem?
Thanks!Wednesday, November 16, 2005 6:53 AM -
This is really not the problem. Quit the contrary it shows another mistake because my computer is working with an ',' for the decimal point. As there is no further answer I have tried a little more and found out if you spent some more spaces it will work.
.Expression = "IIf(price > 0 , price * tax , tax)"
So the case is closed
Wednesday, November 16, 2005 9:18 AM -
So the problem is your computer treat this
"IIf(price > 0, price * tax, tax)"
as
"IIf(price > 0. price * tax, tax)"
And you fix it by
"IIf(price > 0 , price * tax, tax)"
Interesting!Wednesday, November 16, 2005 10:34 PM -
not really; I added one space more.
"IIf(pric > 0 , price * tax , tax)"
buuuuuut
yesterday I installed the latest Version of Visual Studio 2005
Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727
Installed Edition: Professional
and the latest version of MS SQL server 2005( 9.0.1399)
Result :
The problems seem to be fixed. The behaviour is as it was in VS 2003.
Thursday, November 17, 2005 5:42 AM