Just too many table adapters

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
Hi,

This code does not error but simply fills the combobox with loads of rows of the name of the row type rather than the contents?

VB.NET:
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cboNewAutoTransaction.DataSource = glb_dtTransactionDesc.Select([/SIZE][SIZE=2][COLOR=#800000]"auto_tran = 'False'"[/COLOR][/SIZE][SIZE=2])
[/SIZE]

I am trying to use one table adapter rather than creating a new one everytime I need to access the data in the table a different way

Am I going down the wrong road?

Thanks
 
Hi,

yes I have, just did not post that bit...

VB.NET:
Me.cboNewAutoTransaction.DataSource = glb_dtTransactionDesc.Select("auto_tran = 'False'")

Me.cboNewAutoTransaction.DisplayMember = "tran_description"

Me.cboNewAutoTransaction.ValueMember = "tran_id"

but as I say I get the data type rather than the data itself?
 
Yes but that is my point?

I am trying to use the same table adapter for different records so as to reduce the number of tabale adapters used?

This gives me access to the entire datatable
VB.NET:
Me.cboNewAutoTransaction.DataSource = glb_dtTransactionDesc

This gives me access to a subset of the datatable
VB.NET:
Me.cboNewAutoTransaction.DataSource = glb_dtTransactionDesc.Select("auto_tran = 'False'")
 
I had the same problem, I've just checked my code. I think it's because of where your .select is.

Mine works fine with along the lines of;

VB.NET:
Me.cboNewAutoTransaction.DataSource = me.[B]DATASET[/B].Tables("[B]DATATABLE[/B]").Select("auto_tran = 'False'")

You need to change the Dataset and Datatable to what you have, give that a go.

Sorry about my previous post - it does come up with that error if you only set the DataSouce but not the DisplayMember :)
 
Alternative is

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dv [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataView = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataView(glb_dtTransactionDesc)
dv.RowFilter = "auto_tran = 'False'"
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cboNewAutoTransaction.DataSource = dv
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cboNewAutoTransaction.DisplayMember = "tran_description"
[/SIZE]
 
Yes but that is my point?

I am trying to use the same table adapter for different records so as to reduce the number of tabale adapters used?

Stop calling it a tableadapter - it's a datatable

This gives me access to the entire datatable
VB.NET:
Me.cboNewAutoTransaction.DataSource = glb_dtTransactionDesc

yes..

This gives me access to a subset of the datatable
VB.NET:
Me.cboNewAutoTransaction.DataSource = glb_dtTransactionDesc.Select("auto_tran = 'False'")
no. the select command returns an array of data rows. a combo doesnt know how to use an array of datarows in value/display member mode

instead you should fill the datatable once (using a tableadapter :) ) and then have a DataView sit between the table and the combo

The string youre currently passing into the select.. use that as the FILTER of the DataView
 
Hi,

now that I understand that the .select method returns an array of rows I tried the following.

When I choose the required dates I would expect to get 3 rows returned in the array and therefore expect to see 3 displayed in the message box. However what I get is -1 which I presume is saying True there are some rows?

How do I access the count and or contents?

VB.NET:
Dim rwRows() As DataRow

Dim strSQLString As String = "void = 'True' AND tran_date >= '" & dtmDeleteVoidFrom.Value.Date & "' AND tran_date <= '" & dtmDeleteVoidTo.Value.Date.ToString.Substring(0, 10) & " 23:59:59'"

rwRows = glb_dtTransactions.Select(strSQLString)

MessageBox.Show(UBound(rwRows).ToString)


Thanks
 
dtmDeleteVoidTo.Value.Date.ToString.Substring(0, 10)

Aye carumba.. is there something wrong with dtmDeleteVoidTo.ToString("yyyyMMdd") ? :)


We dont use UBound any more.. that's yicky!

MessageBox.Show(rwRows.Length.ToString())

-
ps, didnt you ever use the debugger for this stuff? There's no need to messagebox, just put a breakpoint on the line and point to rwRows with your mouse..
 
Aye carumba.. is there something wrong with dtmDeleteVoidTo.ToString("yyyyMMdd") ? :)

Gad Zooks! seems I am still in old style rut, did not know about this!!

We dont use UBound any more.. that's yicky!

MessageBox.Show(rwRows.Length.ToString())

Yoinks! again......I didn't know that!

ps, didnt you ever use the debugger for this stuff? There's no need to messagebox, just put a breakpoint on the line and point to rwRows with your mouse..

Yeah I use break points, just ol'habits die hard!! :eek:

I find I know lots of VB.NET yet am missing some of the basic stuff.

Trouble is finding a good book to work through lots of this stuff. I find online help and MSDN too painful to use. I always seem to spend ages searching without much success!

Thanks for the pointers tho.....way KOOL:D
 
Here is a good example I want I find difficult to overcome!

VB.NET:
[B]dtmDeleteVoidTo.ToString("yyyyMMdd")
[/B]

errors saying no accessible ToSting accepts this number of arguments?

I then searched the index for ToString and get loads of entries where they say this method not intended to be used directly in your code?

Can someone point me to the 'idiots' guide to locating meaningful help on such things?

Thanks
 
Gad Zooks! seems I am still in old style rut, did not know about this!!



Yoinks! again......I didn't know that!



Yeah I use break points, just ol'habits die hard!! :eek:

Well, as a general rule, avoid anything where youre passing into a function and getting out the answer that you want.

e.g. avoid:
UBound(myArray)
Left(myString, numChars)
CStr(123)

use:
myArray.Length - 1 'an array of length ten runs 0-9, the ubound is length-1 = 9
myString.Substring(0, numChars)
123.ToString() 'looks confusing uh? 123 is an Integer object, withy a .ToString() method


these are ok:
myInt = Convert.ToInt32("123")
myDbl = Double.ParseDouble("123.456")


If youre wondering what is old vb6 legacy compatibility and what is new .net core, go to projectmenu->properties->references and untick the reference to Microsoft.VisualBasic.dll

All uses of CInt, MsgBox (its now MessageBox.Show), Left, InStr, and so on should now become compiler errors, and you can use the modern equivalents. If youre not sure, then ask here but remember that pretty much everything is represented as an object, with properties..

123 is an object, so:
Dim x as Integer
x = 123
x.(blah blah) 'have a look at the properties that x has. Also have a look at the static methods on Integer:
Integer.(blah blah read intellisense)



I find I know lots of VB.NET yet am missing some of the basic stuff.

Trouble is finding a good book to work through lots of this stuff. I find online help and MSDN too painful to use. I always seem to spend ages searching without much success!

Thanks for the pointers tho.....way KOOL:D
Using the debugger seems to be the biggest stumbler.. I might write an article on it soon
 
Here is a good example I want I find difficult to overcome!

VB.NET:
[B]dtmDeleteVoidTo.ToString("yyyyMMdd")[/B]

errors saying no accessible ToSting accepts this number of arguments?

Press F2
Search for DateTime
In the left panel, click System.DateTime
in the right panel look and see ToString(String) As String
CLick on it, and see:

Public Function ToString(ByVal format As String) As String
Member of System.DateTime
Summary:
Converts the value of this instance to its equivalent string representation using the specified format.
Parameters:
format: A format string.
Return Values:
A string representation of value of this instance as specified by format.
Exceptions:
System.FormatException: The length of format is 1, and it is not one of the format specifier characters defined for System.Globalization.DateTimeFormatInfo.-or- format does not contain a valid custom format pattern.

I dont see anywhere where im not allowed to use this in my code?

The format strings are found on msdn, i remember this:

"yyyy MM dd hh mm ss ffffff"

big M = month
little m = minute
because a month is bigger than a minute

same for hours HH = 24 hours, hh = 12 hours, HH is bigger than hh, 24 is bigger than 12

fffffractions of a second
 
Back
Top