Rick_Fla Posted June 4, 2004 Posted June 4, 2004 I tried to look around, but could not find my answer, so here goes. objDataAccess2 is a class I created to get a dataset from a database, very basic. Dim ProgramData As Array 'Get Program Information dsData = objDataAccess2.GetDataSet(mstrConnectionString, strSql, strRecordSetName) ProgramData = dsData.Tables(strRecordSetName).Rows(0).ItemArray() 'Set Form Caption Me.Text = ProgramData(1) & " " & ProgramData(2) The problem I am having is I am getting a late binding error here: Me.Text = ProgramData(1) & " " & ProgramData(2) ProgramData is just an array of the items in the table row. I am trying to assign the text of the form to a field in the database, but get the "Option Strict on disallows late binding" which, I hate to admit, has me stumped. Still learning this stuff :) Quote "Nobody knows what I do until I stop doing it."
Administrators PlausiblyDamp Posted June 4, 2004 Administrators Posted June 4, 2004 How is ProgramData declared? Also it may be worth trying ProgramData(1).ToString() and ProgramData(2).ToString(), but I would still check to see if ProgramData() is declared correctly. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Rick_Fla Posted June 4, 2004 Author Posted June 4, 2004 How is ProgramData declared? Also it may be worth trying ProgramData(1).ToString() and ProgramData(2).ToString(), but I would still check to see if ProgramData() is declared correctly. as an array, I fixed it by doing this, but please let me know if this is not the correct way. Me.Text = CType(ProgramData.GetValue(1), String) & " " & CType(ProgramData.GetValue(2), String) Quote "Nobody knows what I do until I stop doing it."
Administrators PlausiblyDamp Posted June 4, 2004 Administrators Posted June 4, 2004 as an array of what data type? Also you could use the .ToString I showed above rather than the CType. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Rick_Fla Posted June 4, 2004 Author Posted June 4, 2004 as an array of what data type? Also you could use the .ToString I showed above rather than the CType. I declared it like this" Dim ProgramData As Array Then I assigned values to it like this: ProgramData = dsData.Tables(strRecordSetName).Rows(0).ItemArray() Is that enough info? I will try your way with the .toString as well. Thanks for the help. Quote "Nobody knows what I do until I stop doing it."
*Experts* Nerseus Posted June 4, 2004 *Experts* Posted June 4, 2004 I think you declared your variable right, as Array. You'll have to use ToString() to convert or System.Convert.ToString() (but that's the hard way). I'd avoid CType as it's a carryover for converting from VB6. Since you already know some facts about the data you're getting back (the tablename for instance), why not use the column names instead of using ItemArray? Maybe something like: dsData = objDataAccess2.GetDataSet(mstrConnectionString, strSql, strRecordSetName) ProgramData = dsData.Tables(strRecordSetName).Rows(0).ItemArray() Dim val1 As String Dim val2 As String 'Set Form Caption val1= dsData.Tables(strRecordSetName).Rows(0)("col1") val2= dsData.Tables(strRecordSetName).Rows(0)("col2") Me.Text = val1 & " " val2 -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Rick_Fla Posted June 4, 2004 Author Posted June 4, 2004 I think you declared your variable right, as Array. You'll have to use ToString() to convert or System.Convert.ToString() (but that's the hard way). I'd avoid CType as it's a carryover for converting from VB6. Since you already know some facts about the data you're getting back (the tablename for instance), why not use the column names instead of using ItemArray? Maybe something like: dsData = objDataAccess2.GetDataSet(mstrConnectionString, strSql, strRecordSetName) ProgramData = dsData.Tables(strRecordSetName).Rows(0).ItemArray() Dim val1 As String Dim val2 As String 'Set Form Caption val1= dsData.Tables(strRecordSetName).Rows(0)("col1") val2= dsData.Tables(strRecordSetName).Rows(0)("col2") Me.Text = val1 & " " val2 -Nerseus True, I could do that. I guess the main reason I went this way, was to learn arrays and different methods of handling data in VB.NET. I start to use the column names, then went to the array. Is there a performance drawback, or more of a preference deal? Quote "Nobody knows what I do until I stop doing it."
*Experts* Nerseus Posted June 4, 2004 *Experts* Posted June 4, 2004 Well, the fastest is to use the Ordinal position of the column. For performance sake, I truly wouldn't worry about using ItemArray vs. the column name - I'd go with whatever is easier to understand. The only reason to NOT use the column name is if you're opposed to having such a hard-coded string in your code. It's easy to argue which is worse: a hard-coded column name or a hard-coded ordinal position. I'd much rather have the hard-coded column name, but that's just one person's opinion. In almost every scenario, I'd go with the more readable/maintainable code. Don't worry about performance on little things - wait til you have time to do performance analysis and figure out where the big problems are. If you code for performance now you'll only serve to make finding/fixing bugs hard later on. And chances are good that the code you're optimizing now (and maybe make less readable) is NOT going to be where the big bottlenecks are. -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Rick_Fla Posted June 4, 2004 Author Posted June 4, 2004 Thanks for the insight. I will just decide what I feel comfortable with and go from there. :) Thanks again! Quote "Nobody knows what I do until I stop doing it."
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.