Hello everyone,
I'm getting a strange error when I try to bind a combo box to a Dataset.
Here's my code!
Private Sub Get_Data()
Try
Dim sqlcmd = New SqlCommand("Select * from Utility order by
Utility", sqlConn)
daDataAdapter = New SqlDataAdapter
daDataAdapter.SelectCommand = sqlcmd
dsDataSet = New Dataset
daDataAdapter.Fill(dsDataSet, "Utility")
sqlcmd = New SqlCommand("Select * from Adjustments", sqlConn)
daDataAdapter = New SqlDataAdapter
daDataAdapter.SelectCommand = sqlcmd
daDataAdapter.Fill(dsDataSet, "Adjustments")
daRel = New DataRelation("UtilAdjust",
dsDataSet.Tables("Utility").Columns("Code"),
dsDataSet.Tables("Adjustments").Columns("Code"))
dsDataSet.Relations.Add(daRel)
Set_Update_Command()
Set_Insert_Command()
Set_Delete_Command()
Catch ex As Exception
MessageBox.Show(ex.Source.ToString & " - " & ex.Message,
Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub BindFields()
Try
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.DataBindings.Clear()
ctrl.Text = ""
End If
Next
cbUtility.DataBindings.Clear()
cbType.DataBindings.Clear()
For Each ctrl In Me.GroupBox1.Controls
If TypeOf ctrl Is TextBox Then
ctrl.DataBindings.Clear()
ctrl.Text = ""
End If
Next
cbUtility.DataSource = dsDataSet.Tables("Utility")
cbUtility.DisplayMember = "UTILITY"
cbUtility.ValueMember = "CODE"
tbAN.DataBindings.Add("Text", dsDataSet,
"Utility.UtilAdjust.AdjustmentName")
lblAK.DataBindings.Clear()
lblAK.DataBindings.Add("Text", dsDataSet,
"Utility.UtilAdjust.AdjKey")
BindDate(tbASD, "UTILITY.UtilAdjust.AdjStartDate")
BindDate(tbAED, "UTILITY.UtilAdjust.AdjEndDate")
BindCurr(tbAA, "UTILITY.UtilAdjust.adjustment")
BindType(cbType, "UTILITY.UtilAdjust.type")
bmUtil = Me.BindingContext(dsDataSet, "Utility")
bmAdjust = Me.BindingContext(dsDataSet, "UTILITY.UtilAdjust")
AddHandler Me.BindingContext(dsDataSet,
"Utility").PositionChanged, _
AddressOf dtUtil_PositionChanged
Catch ex As Exception
MessageBox.Show(ex.Source.ToString & " - " & ex.Message,
Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
First I get my data by calling Get_Data(), Next I bind my data be calling
BindFields()
I get the following error when I hit these statements. cbUtility = combo
box = System.Windows.Forms.ComboBox
cbUtility.DataSource = dsDataSet.Tables("Utility")
cbUtility.DisplayMember = "UTILITY"
Error:
"Microsoft.VisualBasic - Cast from type 'DataRowView' to type 'String' is
not valid"
Another odd thing is when the exception is raised my "Catch" doesn't pick it
up! I get an error message on those lines and the program keeps going?
Also everything works correctly, all controls are bound correctly, including
that combo box.
THanks, 2 2467
Hi
Where is your table declaration
i.e. Dim ttable As New DataTable("Utility")
It may think "Utility" is a string without that
declaration. -----Original Message----- Hello everyone,
I'm getting a strange error when I try to bind a combo
box to a Dataset.Here's my code!
Private Sub Get_Data() Try Dim sqlcmd = New SqlCommand("Select * from
Utility order byUtility", sqlConn)
daDataAdapter = New SqlDataAdapter daDataAdapter.SelectCommand = sqlcmd
dsDataSet = New Dataset daDataAdapter.Fill(dsDataSet, "Utility")
sqlcmd = New SqlCommand("Select * from
Adjustments", sqlConn) daDataAdapter = New SqlDataAdapter daDataAdapter.SelectCommand = sqlcmd
daDataAdapter.Fill(dsDataSet, "Adjustments")
daRel = New DataRelation("UtilAdjust", dsDataSet.Tables("Utility").Columns("Code"), dsDataSet.Tables("Adjustments").Columns("Code") ) dsDataSet.Relations.Add(daRel)
Set_Update_Command() Set_Insert_Command() Set_Delete_Command()
Catch ex As Exception MessageBox.Show(ex.Source.ToString & " - " &
ex.Message,Application.ProductName, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try
End Sub
Private Sub BindFields() Try Dim ctrl As Control For Each ctrl In Me.Controls If TypeOf ctrl Is TextBox Then ctrl.DataBindings.Clear() ctrl.Text = "" End If Next
cbUtility.DataBindings.Clear() cbType.DataBindings.Clear()
For Each ctrl In Me.GroupBox1.Controls If TypeOf ctrl Is TextBox Then ctrl.DataBindings.Clear() ctrl.Text = "" End If Next
cbUtility.DataSource = dsDataSet.Tables
("Utility") cbUtility.DisplayMember = "UTILITY" cbUtility.ValueMember = "CODE" tbAN.DataBindings.Add("Text", dsDataSet, "Utility.UtilAdjust.AdjustmentName") lblAK.DataBindings.Clear() lblAK.DataBindings.Add("Text", dsDataSet, "Utility.UtilAdjust.AdjKey")
BindDate
(tbASD, "UTILITY.UtilAdjust.AdjStartDate") BindDate
(tbAED, "UTILITY.UtilAdjust.AdjEndDate") BindCurr
(tbAA, "UTILITY.UtilAdjust.adjustment") BindType(cbType, "UTILITY.UtilAdjust.type")
bmUtil = Me.BindingContext
(dsDataSet, "Utility") bmAdjust = Me.BindingContext
(dsDataSet, "UTILITY.UtilAdjust") AddHandler Me.BindingContext(dsDataSet, "Utility").PositionChanged, _ AddressOf dtUtil_PositionChanged
Catch ex As Exception MessageBox.Show(ex.Source.ToString & " - " &
ex.Message,Application.ProductName, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub
First I get my data by calling Get_Data(), Next I bind my
data be callingBindFields()
I get the following error when I hit these statements.
cbUtility = combobox = System.Windows.Forms.ComboBox cbUtility.DataSource = dsDataSet.Tables("Utility") cbUtility.DisplayMember = "UTILITY"
Error: "Microsoft.VisualBasic - Cast from type 'DataRowView' to
type 'String' isnot valid"
Another odd thing is when the exception is raised
my "Catch" doesn't pick itup! I get an error message on those lines and the
program keeps going?Also everything works correctly, all controls are bound
correctly, includingthat combo box.
THanks, .
Mike,
I'm just using the dataset to bind the combo to
Dim sqlcmd = New SqlCommand("Select * from Utility order by
Utility", sqlConn)
daDataAdapter = New SqlDataAdapter
daDataAdapter.SelectCommand = sqlcmd
dsDataSet = New Dataset
daDataAdapter.Fill(dsDataSet, "Utility")
cbUtility.DataSource = dsDataSet.Tables("Utility")
cbUtility.DisplayMember = "UTILITY"
cbUtility.ValueMember = "CODE" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: CGuy |
last post by:
URGENT HELP REQUIRED FROM GURUS
Hi,
I have a custom object that implements ICollection and IListSource. This
object has also an enumerator defined for it which implements IEnumerator
and...
|
by: Ken Powers |
last post by:
Hello everyone,
Sorry about the repost, my second VB.NET App is done with the exception of
this error.
I'm getting a strange error when I try to bind a combo box to a Dataset.
Here's my code!
...
|
by: Ron L |
last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying
to display in a datagrid. This datasource has 4 columns that I am
interested in here, a text column and 3 value columns...
|
by: TS |
last post by:
Hi all,
From my windows form, I opened a connection to a SQL database. Now I need to
generate a combo box from a SELECT statement pointing to the last name column
in the SQL tables. I am stuck...
|
by: Richard |
last post by:
I have created a form which sets up a dataview. The form views one
record at a time using a currencymanager. This works fine. All my
text boxes bind.
However I have a combo box which gets its...
|
by: Steve |
last post by:
C#
I have some combo boxes, full of lookup descriptions. When I retrieve a
dataset for my record, the values that need binding to the combos are the
actual record IDs that relate to these...
|
by: Kay |
last post by:
Hi all,
Could you tell me the best way to add a blank item(as first item) in a data
binded combo box? Because I think I didn't do it right and it generate an
error if the second item(after the...
|
by: =?Utf-8?B?amVmZmVyeQ==?= |
last post by:
i need help with a combo box and this same code works on my first tab with a
combo box. The error or problem i have is this code causes an index out of
range error when i run it on my second combo...
|
by: =?Utf-8?B?ZnJlZGR5?= |
last post by:
I am new to the whole c# thing, I now how to get data from a db into a combo
box. My question is: should I have one table for 5 combo box or have 5 tables
for 5 combo box?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |