Hi all,
I posted this question here before, but I'm still having a problem with this
code.
From my windows form, I opened a connection to a SQL database. I need to
generate a combo box in my form from a SELECT statement that selects the last
name column
from an SQL table. I wrote the following code to do that, but when I run
this code it doesn't do anything!! It doesn't even return an error message to
let me know what's going on!!
All I need is generating this combo box from this table's column in SQL. I
am new to .net. Please help
This is the code I used:
Private Sub ConnectSQL_Clic k(ByVal sender As Object, ByVal e As
System.EventArg s) Handles ConnectSQL.Clic k
Dim SQLEV As SqlClient.SqlCo nnection = New SqlClient.SqlCo nnection
Dim cmd As SqlClient.SqlCo mmand
Dim ClientName As SqlClient.SqlDa taReader
SQLEV.Connectio nString = "Persist Security Info=true;Integ rated
Security=false; User ID=sa;Password= xxxx;database=y yy;server=zzzz"
cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV)
SQLEV.Open()
ClientName = cmd.ExecuteRead er
cbo_ChildName.I tems.Clear()
Do While ClientName.Read
cbo_ChildName.I tems.Add(Client Name.Item("Last _Name").ToStrin g)
Loop
SQLEV.Close()
--
TS 3 1478
Hi TS,
Two ideas:
1. Change the order from
cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV)
SQLEV.Open()
to
SQLEV.Open()
cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV)
2. Do it this way, which I find much easier:
Dim oconn As New SqlConnection(g lobalconnection string)
Dim dabranches As New SqlDataAdapter( "select brname from branches order by
brname", oconn)
Dim dsbranches As New DataSet("dsbran ches")
dabranches.Fill (dsbranches, "dsbranches ")
oconn.Connectio nString = globalconnectio nstring
' you don't really need the connectionstrin g for this, as a dataset opens
its own
oconn.Open()
Dim r As DataRow
For Each r In dsbranches.Tabl es("dsbranches" ).Rows
cbo.Items.Add(r ("brname"))
Next
HTH,
Bernie Yaeger
"TS" <TS@discussions .microsoft.com> wrote in message
news:AB******** *************** ***********@mic rosoft.com... Hi all, I posted this question here before, but I'm still having a problem with this code. From my windows form, I opened a connection to a SQL database. I need to generate a combo box in my form from a SELECT statement that selects the last name column from an SQL table. I wrote the following code to do that, but when I run this code it doesn't do anything!! It doesn't even return an error message to let me know what's going on!! All I need is generating this combo box from this table's column in SQL. I am new to .net. Please help
This is the code I used: Private Sub ConnectSQL_Clic k(ByVal sender As Object, ByVal e As System.EventArg s) Handles ConnectSQL.Clic k Dim SQLEV As SqlClient.SqlCo nnection = New SqlClient.SqlCo nnection Dim cmd As SqlClient.SqlCo mmand Dim ClientName As SqlClient.SqlDa taReader
SQLEV.Connectio nString = "Persist Security Info=true;Integ rated Security=false; User ID=sa;Password= xxxx;database=y yy;server=zzzz" cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV) SQLEV.Open() ClientName = cmd.ExecuteRead er cbo_ChildName.I tems.Clear() Do While ClientName.Read cbo_ChildName.I tems.Add(Client Name.Item("Last _Name").ToStrin g) Loop SQLEV.Close()
-- TS
I can't express how much I am thankful to you. It worked. One more thing, if
I want to include last name as well as first name in the combo box, what
change I have to make in the code?
Currently the code reads as:
cbo_ChildName.I tems.Add(Client Name.Item("Last _Name").ToStrin g)
Thanks again for all your help.
"Bernie Yaeger" wrote: Hi TS,
Two ideas: 1. Change the order from cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV) SQLEV.Open() to SQLEV.Open() cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV) 2. Do it this way, which I find much easier: Dim oconn As New SqlConnection(g lobalconnection string)
Dim dabranches As New SqlDataAdapter( "select brname from branches order by brname", oconn)
Dim dsbranches As New DataSet("dsbran ches")
dabranches.Fill (dsbranches, "dsbranches ")
oconn.Connectio nString = globalconnectio nstring
' you don't really need the connectionstrin g for this, as a dataset opens its own
oconn.Open()
Dim r As DataRow
For Each r In dsbranches.Tabl es("dsbranches" ).Rows
cbo.Items.Add(r ("brname"))
Next
HTH,
Bernie Yaeger
"TS" <TS@discussions .microsoft.com> wrote in message news:AB******** *************** ***********@mic rosoft.com... Hi all, I posted this question here before, but I'm still having a problem with this code. From my windows form, I opened a connection to a SQL database. I need to generate a combo box in my form from a SELECT statement that selects the last name column from an SQL table. I wrote the following code to do that, but when I run this code it doesn't do anything!! It doesn't even return an error message to let me know what's going on!! All I need is generating this combo box from this table's column in SQL. I am new to .net. Please help
This is the code I used: Private Sub ConnectSQL_Clic k(ByVal sender As Object, ByVal e As System.EventArg s) Handles ConnectSQL.Clic k Dim SQLEV As SqlClient.SqlCo nnection = New SqlClient.SqlCo nnection Dim cmd As SqlClient.SqlCo mmand Dim ClientName As SqlClient.SqlDa taReader
SQLEV.Connectio nString = "Persist Security Info=true;Integ rated Security=false; User ID=sa;Password= xxxx;database=y yy;server=zzzz" cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV) SQLEV.Open() ClientName = cmd.ExecuteRead er cbo_ChildName.I tems.Clear() Do While ClientName.Read cbo_ChildName.I tems.Add(Client Name.Item("Last _Name").ToStrin g) Loop SQLEV.Close()
-- TS
Hi TS,
You're very welcome.
Here's the change:
this
cbo_ChildName.I tems.Add(Client Name.Item("Last _Name").ToStrin g)
changes to this
cbo_ChildName.I tems.Add(Trim(C lientName.Item( "First_Name").T oString) & " " &
ClientName.Item ("Last_Name").T oString)
Notice that I put first name first and trimmed it so that it is no longer
than the letters in the first name; then I added one space; then the last
name.
HTH,
Bernie
"TS" <TS@discussions .microsoft.com> wrote in message
news:F0******** *************** ***********@mic rosoft.com... I can't express how much I am thankful to you. It worked. One more thing, if I want to include last name as well as first name in the combo box, what change I have to make in the code? Currently the code reads as: cbo_ChildName.I tems.Add(Client Name.Item("Last _Name").ToStrin g)
Thanks again for all your help.
"Bernie Yaeger" wrote:
Hi TS,
Two ideas: 1. Change the order from cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV) SQLEV.Open() to SQLEV.Open() cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV) 2. Do it this way, which I find much easier: Dim oconn As New SqlConnection(g lobalconnection string)
Dim dabranches As New SqlDataAdapter( "select brname from branches order by brname", oconn)
Dim dsbranches As New DataSet("dsbran ches")
dabranches.Fill (dsbranches, "dsbranches ")
oconn.Connectio nString = globalconnectio nstring
' you don't really need the connectionstrin g for this, as a dataset opens its own
oconn.Open()
Dim r As DataRow
For Each r In dsbranches.Tabl es("dsbranches" ).Rows
cbo.Items.Add(r ("brname"))
Next
HTH,
Bernie Yaeger
"TS" <TS@discussions .microsoft.com> wrote in message news:AB******** *************** ***********@mic rosoft.com... > Hi all, > I posted this question here before, but I'm still having a problem with > this > code. > From my windows form, I opened a connection to a SQL database. I need > to > generate a combo box in my form from a SELECT statement that selects > the > last > name column > from an SQL table. I wrote the following code to do that, but when I > run > this code it doesn't do anything!! It doesn't even return an error > message > to > let me know what's going on!! > All I need is generating this combo box from this table's column in > SQL. I > am new to .net. Please help > > This is the code I used: > Private Sub ConnectSQL_Clic k(ByVal sender As Object, ByVal e As > System.EventArg s) Handles ConnectSQL.Clic k > Dim SQLEV As SqlClient.SqlCo nnection = New > SqlClient.SqlCo nnection > Dim cmd As SqlClient.SqlCo mmand > Dim ClientName As SqlClient.SqlDa taReader > > SQLEV.Connectio nString = "Persist Security Info=true;Integ rated > Security=false; User ID=sa;Password= xxxx;database=y yy;server=zzzz" > cmd = New SqlClient.SqlCo mmand("SELECT * FROM qmf_cint", SQLEV) > SQLEV.Open() > ClientName = cmd.ExecuteRead er > cbo_ChildName.I tems.Clear() > Do While ClientName.Read > > cbo_ChildName.I tems.Add(Client Name.Item("Last _Name").ToStrin g) > Loop > SQLEV.Close() > > > -- > TS This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: will eichert |
last post by:
Greetings. I have a problem with a combo box incorrectly displaying
blank items when returning to a form from a modal form. It's fine when
the main form first comes up, but gets messed up when the main form is
reactivated following opening and closing a modal form. Strangely,
this was not a problem until I started using my Access 2000 db in
Access 2003 (as an Access 2000 db). Details follow...
I have an unbound combo box on my main form...
|
by: Nikolay Petrov |
last post by:
I have asked a question before some time, and a guy responded to it. His
answer raised new questions and I replied them back, but still no answer. I
need them urgently so I am to post the whole thing again. I've found that
nobody looks at the older threads ;-(
My Question was:
I have a Combo box, binded to a dataset
With cmbCompany
.DataSource = dsSpecContact
.DisplayMember = "Companies.CompanyName"
|
by: http://www.visual-basic-data-mining.net/forum |
last post by:
Hi...
Say i have this string call "data" in Form1, this string contains number "5"
value....
how do i pass this string to the Form2 and compare with the combo box
items...
The combo box DropDownStyle is set to DropDownList...
which means when i pass, the SelectedIndex must be subtract or add by 1 to
|
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 with the code I should use to generate this
combo box. I used to use ADO to open a connection to SQL in VB6 then use Do
until EOF - Loop to loop through the recodset and the cbo.additems to place
the result of the recordset in the combo box. With...
|
by: Tgavin8 |
last post by:
Hi
I am currently attempting to build a databse for a clothing company. The price can differ for this company depending on the size so in the products table I have the sizes listed in a subform linked by ProductID.
The issue is when creating the invoice - on the Sales line items I have the productID pulling through the description for the products table followed by the SIZEID which I am trying to filter down depending on the selection made...
| |
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 box:
(errored code) Select Case ComboBox2.text
Case Is ="Execute Program"
'code to execute program here
Case Is ="Other Command that executes code at a certain time"
' code below the same as above except that it works
But not my first(this...
|
by: creative1 |
last post by:
Hi,
I am designing a data entry JSP form to add payment information. I want to add a combo box on the form that would have list of the compies present in databse. The combo should be populated based on the data in the databse. Can someone give a source code to do that?
I don't have anything to show you guys. I tried various examples but no luck.
I am using mySQL as databse.
I am using beans to display payment information on the same form....
|
by: mygirl22 |
last post by:
Hi,
I used this code to created 2 combo boxes General and Specific...and Only show Specific (Combo B) when Combo A is chosen.....
What i need now is to know how to assign specific values to the items in combo b (Specific).???
If i chose a sode, Fanta, i want the total price to be $20.00 (this price will show up in the finial price box....Please Help!!
drinkComboBox.Items.Clear() 'Clears the old items out of the drinkComboBox
...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |