Question converted code not working; Vb6.0 to VB.Net

sonofspm

New member
Joined
Nov 27, 2008
Messages
1
Programming Experience
1-3
Hi,

I need to convert some vb 6.0 code into vb.net.
VB.NET:
If code looks like 
If adoRS("ENABLE") = 1 Then
            If adoRS("STOCK_Available") = 1 Then
......

If I write the same code in VB.Net with the help of Dataset; like
VB.NET:
If objDs.Tables(0).Columns("ENABLE") = 1 Then 
....
End If
it gives me an error.
or If I write
VB.NET:
 If objDs.Tables(0).Columns("ENABLE").DefaultValue = 1 Then
....
End If
there is no error but I'm not sure whether it will result correctly.

Please suggest how to do this.

--Shubh Maitrey
 
Last edited by a moderator:
Er

You know the difference between a column and a row, right?

'get the value out of the 13th row of myTable, in column myColumnName
dataset.Tables("myTable").Rows(12).Item("myColumnName")


The .Columns collection is for modifying the datatable schema.. Your code kinda points to a small confusion you have in equivalences between an ADO Recordset and a datatable. Take a read of the sticky in this forum and in the Data Access forum


See the DW2 link in my signature for info on how you should be doing your data access
 
@cjard is right , you can follow his DW2 link ....


in short i want to explain you something ....

in vb6 adoRS is giving you a row .... and you just select the column index or name for getting value, am I correct ?

bt in vb.net ....dataset is just a collection of tables and vb6 adoRs is just a Table(imagine)...and in vb6.. adoRs have selected your current row where are you working and u just put the column name or index to get the value ;on the other hand in vb.net, you have to find out ..the row you want to work with, if you want to get row cell by dataset.

So if you want to select a row specific cell information.. first you have to do is specifically tell your dataset that which table you want to work with .. then which row, then column ..

In your case,by this command your getting information abt the current coulmn..
objDs.Tables(0).Columns("ENABLE") = 1
Columns("ENABLE"), column name ,coulmn maxlenght , default value .. etc


and if you understand what @cjard says...

VB.NET:
dataset.Tables("myTable").Rows(12).Item("myColumnN ame")

you will have a better result....

there are many ways to find records.. its very simple and by this way you can search only from those table which has primary field....

Row find By Primarykeyfield command from dataset by (it will help to find the index):
VB.NET:
indexRow=dataset.Tables("myTable").Rows.Find(FindText)
'this text will find and give result from unique column

------for @cjard bro...
thanks for warning me.....
i have tried to reply you something in msg bt your msgbox is full so i can't
and i will not post in before records again.. and i love this forum
 
Back
Top