-
updating code
I have been assigned the task of updating some code which was written in an older version of vb. I am unfamiliar with the code and havent programmed in vb in quite a while.
This function is giving me a syntax error. How would you suggest to fix this function?
Code:
Public Function bindthissql_ODBC(ByVal fds As Object, ByVal fsql As Object) As Object
New OdbcDataAdapter(StringType.FromObject(fsql), Me.dbconn).Fill(DirectCast(fds, DataSet), "Thedata")
Return New DataView(DirectCast(LateBinding.LateGet(fds, Nothing, "Tables", New Object() { "Thedata" }, Nothing, Nothing), DataTable))
End Function
-
Re: updating code
Is that code from a VB6 project upgraded to VB.NET? What's the error message?
-
Re: updating code
I am thinking originally it may have been vb6. I have just taken over this project so i am unaware of what has been done beforehand. The only error msg VS 2008 gives me is Syntax error.
-
Re: updating code
When you build it or when you run it?
My suggestion would be to rewrite that function yourself.
-
Re: updating code
When i try to run through VS in debug mode. I am not familliar with the code used in this and am lost in rewriting the function. If someone can understand what is happening here and do a quick rewrite it would be greatly appreciated.
-
Re: updating code
When you get rid of all the late binding the method is rather simple. It takes a DataSet and a String containing an SQL query, then populates a DataTable in the DataSet and returns a new DataView of that table. I'd suggest you write a method from scratch that does that.
-
Re: updating code
This is what i have come up with. It shows no errors in VS but i have not tested it in tha actual ap yet. does this look correct?
Code:
Public Function bindthissql_SQL(ByVal fds As Object, ByVal fsql As Object) As Object
Dim MyAdapter As New SqlDataAdapter(StringType.FromObject(fsql), Me.dbconn3)
MyAdapter.Fill(DirectCast(fds, DataSet), "Thedata")
Return New DataView(DirectCast(LateBinding.LateGet(fds, Nothing, "Tables", New Object() { "Thedata" }, Nothing, Nothing), DataTable))
End Function
-
Re: updating code
I said get rid of all the late binding. If the values passed in are a particular type then declare them so. If the value returned is a particular type then declare it so. Then there's no need for casting or any of that other silliness.