Hi, I have a huge problem which drives crazy for a month... I am
working on a database program and I am using .net2005 and Sql server
2003. In a form I have a listbox and two texboxes and there's also in
my database a table with three sells: "name", "e-mail" and "address".
The listbox shows the "name" and I want when I choose a name, the two
textboxes to show the other two sells ("name","addres s") that goes for
the name i chose in the table. And guess what? I don't know how!!! I
know I have something like "SELECT...FROM. ..WHERE...LIKE. .." but the
best think I ever got is "false" in the two textboxes... Please tell
how to do that and also in which listbox's event I have to do this?
PLEASE HELP ME !!!! IT'S ARGENT !!! Thanx a lot =) 10 1794
On 31 Lug, 13:14, SanMigue...@gma il.com wrote:
Hi, I have a huge problem which drives crazy for a month... I am
working on a database program and I am using .net2005 and Sql server
2003. In a form I have a listbox and two texboxes and there's also in
my database a table with three sells: "name", "e-mail" and "address".
The listbox shows the "name" and I want when I choose a name, the two
textboxes to show the other two sells ("name","addres s") that goes for
the name i chose in the table. And guess what? I don't know how!!! I
know I have something like "SELECT...FROM. ..WHERE...LIKE. .." but the
best think I ever got is "false" in the two textboxes... Please tell
how to do that and also in which listbox's event I have to do this?
PLEASE HELP ME !!!! IT'S ARGENT !!! Thanx a lot =)
it may become Gold if you post some code and a better explanation :-)
T
look I am not very good at .net and sql (and I am trying something
difficult? very clever of me =D) but I will do my best.
this is the best thing I've managed to do and it's not working.
Private Sub Customers_Load( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
CustomersTableA dapter1.Fill(_D ol_Ammad_E_Stor e_DataSet11.Cus tomers)
End Sub
Private Sub ListBox1_Displa yMemberChanged( ByVal sender As Object,
ByVal e As System.EventArg s) Handles ListBox1.Displa yMemberChanged
Using connection As New SqlClient.SqlCo nnection("Data
Source=DRJAMES; Initial Catalog=Dol-Ammad(E-Store);Integrat ed
Security=True;" )
connection.Open ()
Using command As New SqlClient.SqlCo mmand("SELECT [e-mail]
>From Customers WHERE Name = '" & ListBox1.Select edItem & "'",
connection)
TextBox2.Text = command.Execute Scalar.ToString
End Using
End Using
End Sub
Now, I don't know what else to sent you and to be honest I don't have
anything else done on this problem... If need something else tell me
what and I'll try to sent it. Thanx for your interest.
<Sa*********@gm ail.comschrieb
Hi, I have a huge problem which drives crazy for a month... I am
working on a database program and I am using .net2005 and Sql server
2003. In a form I have a listbox and two texboxes and there's also
in my database a table with three sells: "name", "e-mail" and
"address". The listbox shows the "name" and I want when I choose a
name, the two textboxes to show the other two sells
("name","addres s") that goes for the name i chose in the table. And
guess what? I don't know how!!! I know I have something like
"SELECT...FROM. ..WHERE...LIKE. .." but the best think I ever got is
"false" in the two textboxes... Please tell how to do that and also
in which listbox's event I have to do this? PLEASE HELP ME !!!! IT'S
ARGENT !!! Thanx a lot =)
Assuming that the record exists and the name is unique:
'untested:
Private Sub ListBox1_Select edIndexChanged( _
ByVal sender As System.Object, ByVal e As System.EventArg s) _
Handles ListBox1.Select edIndexChanged
Dim name As String
Dim cmd As SqlCommand
Dim dr As SqlDataReader
name = ListBox1.Select edItem.ToString
cmd = New SqlCommand("sel ect * from persons where name = @name")
cmd.Parameters. Add("@name", SqlDbType.NVarC har, 50).Value = name
dr = cmd.ExecuteRead er
dr.Read()
txtAddress.Text = dr("address").T oString
txtEMail.Text = dr("[e-mail]").ToString
dr.Close()
End Sub
Though, is the name unique? If yes, why do you use LIKE, and if no, what if
there are several records with the same name?
Armin
On 31 Lug, 13:54, SanMigue...@gma il.com wrote:
look I am not very good at .net and sql (and I am trying something
difficult? very clever of me =D) but I will do my best.
this is the best thing I've managed to do and it's not working.
Private Sub Customers_Load( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
CustomersTableA dapter1.Fill(_D ol_Ammad_E_Stor e_DataSet11.Cus tomers)
End Sub
Private Sub ListBox1_Displa yMemberChanged( ByVal sender As Object,
ByVal e As System.EventArg s) Handles ListBox1.Displa yMemberChanged
Using connection As New SqlClient.SqlCo nnection("Data
Source=DRJAMES; Initial Catalog=Dol-Ammad(E-Store);Integrat ed
Security=True;" )
connection.Open ()
Using command As New SqlClient.SqlCo mmand("SELECT [e-mail]>From Customers WHERE Name = '" & ListBox1.Select edItem & "'",
connection)
TextBox2.Text = command.Execute Scalar.ToString
End Using
End Using
End Sub
Now, I don't know what else to sent you and to be honest I don't have
anything else done on this problem... If need something else tell me
what and I'll try to sent it. Thanx for your interest.
try ExecuteReader and get the field values you need.
ExecuteScalar returns 1 value and there is no way you can fill 2
TexBoxes with 1 value.
Further, that value may not be what you want, as for instance is a
field of no interest to you.
T
Yes the name is unique and I was using LIKE in this way:
SqlDataAdapter1 .SelectCommand. CommandText = "SELECT e-mail FROM
persons WHERE name LIKE '" & ListBox1.Text & "'"
TextBox2.Text = SqlDataAdapter1 .ToString
I tried what you sent me but still nothing happend. =( there's no
problem with the code, the program runs without faults and when I
change the listbox item the two textboxes remain empty. WHY???????? I
know that the solution is like the one you sent but it doesn't work.
"Armin Zingler" <az*******@free net.deschrieb
>
cmd = New SqlCommand("sel ect * from persons where name = @name")
Sry, forgot the connection:
cmd = New SqlCommand("sel ect * from persons where name = @name", con)
And too many brackets:
txtEMail.Text = dr("[e-mail]").ToString
txtEMail.Text = dr("e-mail").ToString
Armin
<Sa*********@gm ail.comschrieb
Yes the name is unique and I was using LIKE in this way:
SqlDataAdapter1 .SelectCommand. CommandText = "SELECT e-mail FROM
persons WHERE name LIKE '" & ListBox1.Text & "'"
TextBox2.Text = SqlDataAdapter1 .ToString
I'm a bit confused because, in the other posting
a) you don't use LIKE
b) the last line is
TextBox2.Text = command.Execute Scalar.ToString
c) you use Listbox1.Select edItem, not Listbox1.Text
The latter shouldn't work if you enable Option Strict.
Armin
Oh, sorry. My fault! Let's forget completely the LIKE thing and all
the stupid code I wrote... ( I told you that obviously I was writting
whatever I found because it's almost a month I am trying to fix this,
so everything is wrong!!!).
Now, the code I am using right now - and still not working... - is
this:
Private Sub ListBox1_Select edIndexChanged( ByVal sender As
System.Object, ByVal e As System.EventArg s)
Dim name As String
Dim cmd As SqlClient.SqlCo mmand
Dim dr As SqlClient.SqlDa taReader
name = ListBox1.Select edItem.ToString
cmd = New SqlClient.SqlCo mmand("SELECT * FROM Customers WHERE
name = @name", SqlConnection1)
cmd.Parameters. Add("@name", SqlDbType.NVarC har, 50).Value =
name
dr = cmd.ExecuteRead er
dr.Read()
TextBox3.Text = dr("address").T oString
TextBox2.Text = dr("E-mail").ToString
dr.Close()
End Sub
Do you find anything wrong???
<Sa*********@gm ail.comschrieb
Oh, sorry. My fault! Let's forget completely the LIKE thing and all
the stupid code I wrote... ( I told you that obviously I was
writting whatever I found because it's almost a month I am trying to
fix this, so everything is wrong!!!).
Now, the code I am using right now - and still not working... - is
this:
Private Sub ListBox1_Select edIndexChanged( ByVal sender As
System.Object, ByVal e As System.EventArg s)
Dim name As String
Dim cmd As SqlClient.SqlCo mmand
Dim dr As SqlClient.SqlDa taReader
name = ListBox1.Select edItem.ToString
cmd = New SqlClient.SqlCo mmand("SELECT * FROM Customers WHERE
name = @name", SqlConnection1)
cmd.Parameters. Add("@name", SqlDbType.NVarC har, 50).Value =
name
dr = cmd.ExecuteRead er
dr.Read()
TextBox3.Text = dr("address").T oString
TextBox2.Text = dr("E-mail").ToString
dr.Close()
End Sub
Do you find anything wrong???
No, nothing wrong.
Are you sure you connected to the right database? Right table? Really no
duplicate names?
I guess you have checked this alredy, but...
Is it possible that you can send me the project via e-mail?
Use the sender address of this post and insert a "_" between "no" and
"spam".
Armin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Raj |
last post by:
Hi all,
Can anyone help me with a script which would delete files or
move them to a different folder at some scheduled time..!
Please.....!!!
Thanks in advance...
|
by: Thue Tuxen Sørensen |
last post by:
Hi everybody !
I´m maintaining a large intranet (approx 10000 concurrent users) running on
one IIS box and one DB box with sqlserver 2000.
Currently there is 2,5 GB Ram, 1 1400 mhz cpu and 2 scsi disks installed on
the db box.
Sqlserver is set to use max 1,4 GB RAM, and the sqlserver does not seem to
be using it all.
|
by: Megan |
last post by:
Hi-
I'm creating a database of music bands with their cds and songs.
I'm trying to program an SQL statement so that I can enter a string of
text in a textbox, press the 'Enter' key, and have it return the
associated records to a listbox. Once the listbox has the records, I
want to select a record, which will open a form associated with the
selected record in the listbox.
|
by: Melissa Cowan |
last post by:
I am using Access 2000. I have the Developer's handbook and got the
code for the mulit select listbox from there. It sends the selected
value to another listbox, lstselected. What I need to do is loop
through there and add each item to a table. I can add the other info
fromt he form to a table, just not the otems in the listbox. It only
shows as 0. I tried using the varItem and it told me that the action
is not supported. I'm a bit rusty...
|
by: Edward |
last post by:
I am having a terrible time getting anything useful out of a listbox
on my web form.
I am populating it with the results from Postcode lookup software, and
it is showing the results fine. What I want to do is to allow the
user to click on the row that corresponds to the correct address, and
have the code behind populate the form's Address1, Address2 etc.
controls with the relevant data items.
I put the code for this into the...
| |
by: BigAl.NZ |
last post by:
Hi Guys,
I am trying to write/copy some code that uses events with a GPS.
Everytime the GPS position updates the event fires.
The GPS code is from a SDK Library that I got called GPS Tools from
www.franson.com
For some reason my code below doesnt work - the GpsFixEvent never seems
to "fire" as it were.
|
by: colleen1980 |
last post by:
Hi: I am trying to pull all the values from the listbox. But the ASP
code shows only the last record. Needs help
HTML
<html>
<head>
|
by: zdrakec |
last post by:
Hello all:
Clearly, I'm not getting it! Here is the scenario:
On a web page, I have two list boxen and a text box. The first listbox
is populated at page load time (if it is not a postback). This listbox
has AutoPostback = True. When the user selects an item from this list,
the second listbox is populated with more items relevant to this
selection. I am using an SQLDataSource web control for this. These
items are headers. I want, when...
|
by: teddymeu |
last post by:
Hi Guys, this is kinda complicated but ill do my best to explain.
I have two tables. products and categories. Products holds product info and an image, its primary key is ProductID. Category table holds a category name and description and a primary key CategoryID. The producs table holds a Foreign key field called CategoryID which points to the CategoryID Primary key of the catgory table.
Ok i have two asp.net 2 vb forms. One is using a...
|
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: 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: 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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| | |