473,395 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

need help - -PLEASE

I have a web page that displays contact people in a drop down.
the users selects a person then clicks the go button.
The datagrid should pop with all the information on the select contact
person, correct?

Well, now my issue. I have 5 contact names in the drop down, (pop from DB)
when I select one nothing happens except for one name. I only get
information back for only one person, nothing happens if i select a
different name. The grid comes back blank, but is populated if I pick a
certain name. What would cause this to happen?

here is the code for the drop down.
if (!IsPostBack)
{
SqlDataAdapter myCommand = new SqlDataAdapter("select distinct
contact_person from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "contact_persons");
MySelect.DataSource= ds.Tables["contact_persons"].DefaultView;
MySelect.DataBind();
}

code for the grid:
public void GetTask_Click(Object sender, EventArgs E)
{
String selectCmd = "select * from authors where contact_person =
@contact_person";

SqlConnection myConnection = new
SqlConnection("server=server;database=db;Trusted_C onnection=yes");

SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);

myCommand.SelectCommand.Parameters.Add(new SqlParameter("@contact_person",
SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@contact_person"].Value =
MySelect.SelectedItem.Value;

DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
MyDataGrid.DataSource= ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();
}
since this code correctly agains the pubs db authors table, i took that
table and put it in my Database to verify it wasn't a db issue, that worked
fine, when took that table and made column name changes, and data changes -
nothing. I only get information for 1 person.

need help

thnx


Nov 18 '05 #1
3 1509
I have
MySelect.DataValueField = "contact_person";
MySelect.DataTextField = "contact_person";

set in the properties not the code;
As for part 2, I don't understand what you are saying? I do get the grid
populated with a certain name is selected.


"Suresh" <an*******@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
Mike,
One thing I noticed in your drop down list population code is that you haven't set the DataTextField and DataValueField for your drop down list
object.
myCommand.Fill(ds, "contact_persons");
//added lines
MySelect.DataValueField = "contact_person";
MySelect.DataTextField = "contact_person";
//done add
MySelect.DataSource= ds.Tables["contact_persons"].DefaultView;
MySelect.DataBind();

Slightly modify your drop down list populate query like the following:

SqlDataAdapter myCommand = new SqlDataAdapter("select distinct
contact_person as 'contact_person' from Authors", myConnection);

Note: In your click event handler you are setting the following filter:
myCommand.SelectCommand.Parameters["@contact_person"].Value =
MySelect.SelectedItem.Value;

But in your code you were never setting the value propery of your MySelect drop down object. Setting the DataTextField and DataValueField properties
should fix your problem.
Suresh.

----- Mike wrote: -----

I have a web page that displays contact people in a drop down.
the users selects a person then clicks the go button.
The datagrid should pop with all the information on the select contact person, correct?

Well, now my issue. I have 5 contact names in the drop down, (pop from DB) when I select one nothing happens except for one name. I only get
information back for only one person, nothing happens if i select a
different name. The grid comes back blank, but is populated if I pick a certain name. What would cause this to happen?

here is the code for the drop down.
if (!IsPostBack)
{
SqlDataAdapter myCommand = new SqlDataAdapter("select distinct
contact_person from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "contact_persons");
MySelect.DataSource= ds.Tables["contact_persons"].DefaultView;
MySelect.DataBind();
}

code for the grid:
public void GetTask_Click(Object sender, EventArgs E)
{
String selectCmd = "select * from authors where contact_person =
@contact_person";

SqlConnection myConnection = new
SqlConnection("server=server;database=db;Trusted_C onnection=yes");

SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@contact_person", SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@contact_person"].Value =
MySelect.SelectedItem.Value;

DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
MyDataGrid.DataSource= ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();
}
since this code correctly agains the pubs db authors table, i took that table and put it in my Database to verify it wasn't a db issue, that worked fine, when took that table and made column name changes, and data changes - nothing. I only get information for 1 person.

need help

thnx


Nov 18 '05 #2
>As for part 2, I don't understand what you are saying? I do get the gri
populated with a certain name is selected
I don't know but you are matching against something for the selection against your database

More checks then..

You indicated you set the following
MySelect.DataValueField = "contact_person"

Then you have this line in your click handler method
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@contact_person", SqlDbType.NVarChar, 2))

You've set the length of this parameter to 2. This will truncate the value you set for this parameter to size of 2 characters
What is the value that is being returned for the contact_person exactly? I think you want to set this value to some ID field that's associated with the contact person

Just as a test in debug mode check what value does this parameter have?
myCommand.SelectCommand.Parameters["@contact_person"].Value
after the following line is executed

myCommand.SelectCommand.Parameters["@contact_person"].Value = MySelect.SelectedItem.Value

Suresh

----- Mike wrote: ----

I hav
MySelect.DataValueField = "contact_person"
MySelect.DataTextField = "contact_person"

set in the properties not the code
As for part 2, I don't understand what you are saying? I do get the gri
populated with a certain name is selected


"Suresh" <an*******@discussions.microsoft.com> wrote in messag
news:32**********************************@microsof t.com.. Mike
One thing I noticed in your drop down list population code is that yo haven't set the DataTextField and DataValueField for your drop down lis
object
myCommand.Fill(ds, "contact_persons")

//added line
MySelect.DataValueField = "contact_person"
MySelect.DataTextField = "contact_person"
//done ad
MySelect.DataSource= ds.Tables["contact_persons"].DefaultView
MySelect.DataBind()
Slightly modify your drop down list populate query like the following
SqlDataAdapter myCommand = new SqlDataAdapter("select distinc

contact_person as 'contact_person' from Authors", myConnection)
Note: In your click event handler you are setting the following filter

myCommand.SelectCommand.Parameters["@contact_person"].Value
MySelect.SelectedItem.Value
But in your code you were never setting the value propery of your MySelec drop down object. Setting the DataTextField and DataValueField propertie
should fix your problem Suresh
----- Mike wrote: ----
I have a web page that displays contact people in a drop down

the users selects a person then clicks the go button
The datagrid should pop with all the information on the selec

contac person, correct
Well, now my issue. I have 5 contact names in the drop down, (po from DB
when I select one nothing happens except for one name. I only ge
information back for only one person, nothing happens if i select
different name. The grid comes back blank, but is populated if I pic certain name. What would cause this to happen
here is the code for the drop down if (!IsPostBack

SqlDataAdapter myCommand = new SqlDataAdapter("select distinc
contact_person from Authors", myConnection)
DataSet ds = new DataSet()
myCommand.Fill(ds, "contact_persons")
MySelect.DataSource= ds.Tables["contact_persons"].DefaultView
MySelect.DataBind()
code for the grid

public void GetTask_Click(Object sender, EventArgs E

String selectCmd = "select * from authors where contact_person
@contact_person"
SqlConnection myConnection = ne

SqlConnection("server=server;database=db;Trusted_C onnection=yes")
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd

myConnection); myCommand.SelectCommand.Parameters.Add(new

SqlParameter("@contact_person", SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@contact_person"].Value =
MySelect.SelectedItem.Value;
DataSet ds = new DataSet(); myCommand.Fill(ds, "Authors");
MyDataGrid.DataSource= ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();
}
since this code correctly agains the pubs db authors table, i took

that table and put it in my Database to verify it wasn't a db issue, that worked fine, when took that table and made column name changes, and data changes - nothing. I only get information for 1 person.
need help
thnx
>

Nov 18 '05 #3
I got it thanks, what helped is that you pointed out
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@contact_person",
SqlDbType.NVarChar, 2)); 2 is only looking at the first 2 bytes of the
field, if I change that to read entire field it works. thanks for your help.

"Suresh" <an*******@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
As for part 2, I don't understand what you are saying? I do get the grid
populated with a certain name is selected.
I don't know but you are matching against something for the selection

against your database.
More checks then...

You indicated you set the following:
MySelect.DataValueField = "contact_person";

Then you have this line in your click handler method.
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@contact_person", SqlDbType.NVarChar, 2));
You've set the length of this parameter to 2. This will truncate the value you set for this parameter to size of 2 characters. What is the value that is being returned for the contact_person exactly? I think you want to set this value to some ID field that's associated with
the contact person.
Just as a test in debug mode check what value does this parameter have?
myCommand.SelectCommand.Parameters["@contact_person"].Value
after the following line is executed.

myCommand.SelectCommand.Parameters["@contact_person"].Value = MySelect.SelectedItem.Value;
Suresh.

----- Mike wrote: -----

I have
MySelect.DataValueField = "contact_person";
MySelect.DataTextField = "contact_person";

set in the properties not the code;
As for part 2, I don't understand what you are saying? I do get the grid populated with a certain name is selected.


"Suresh" <an*******@discussions.microsoft.com> wrote in message
news:32**********************************@microsof t.com...
> Mike,
> One thing I noticed in your drop down list population code is that you
haven't set the DataTextField and DataValueField for your drop down list object. >> myCommand.Fill(ds, "contact_persons"); > //added lines
> MySelect.DataValueField = "contact_person";
> MySelect.DataTextField = "contact_person";
> //done add
> MySelect.DataSource= ds.Tables["contact_persons"].DefaultView;
> MySelect.DataBind();
>> Slightly modify your drop down list populate query like the following: >> SqlDataAdapter myCommand = new SqlDataAdapter("select distinct

> contact_person as 'contact_person' from Authors", myConnection);
>> Note: In your click event handler you are setting the following filter:
> myCommand.SelectCommand.Parameters["@contact_person"].Value =
> MySelect.SelectedItem.Value;
>> But in your code you were never setting the value propery of your
MySelect drop down object. Setting the DataTextField and DataValueField properties should fix your problem. >> Suresh.
>> ----- Mike wrote: -----
>> I have a web page that displays contact people in a drop
down.
> the users selects a person then clicks the go button.
> The datagrid should pop with all the information on the select contact
> person, correct?
>> Well, now my issue. I have 5 contact names in the drop down,
(pop from DB)
> when I select one nothing happens except for one name. I only
get > information back for only one person, nothing happens if i select a > different name. The grid comes back blank, but is populated if I pick a
> certain name. What would cause this to happen?
>> here is the code for the drop down. > if (!IsPostBack)
> {
> SqlDataAdapter myCommand = new SqlDataAdapter("select distinct
> contact_person from Authors", myConnection);
> DataSet ds = new DataSet();
> myCommand.Fill(ds, "contact_persons");
> MySelect.DataSource= ds.Tables["contact_persons"].DefaultView;
> MySelect.DataBind();
> }
>> code for the grid:

> public void GetTask_Click(Object sender, EventArgs E)
> {
> String selectCmd = "select * from authors where contact_person

= > @contact_person";
>> SqlConnection myConnection = new

>

SqlConnection("server=server;database=db;Trusted_C onnection=yes"); >> SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd,

myConnection); >> myCommand.SelectCommand.Parameters.Add(new

SqlParameter("@contact_person",
> SqlDbType.NVarChar, 2));
> myCommand.SelectCommand.Parameters["@contact_person"].Value =
> MySelect.SelectedItem.Value;
>> DataSet ds = new DataSet();

> myCommand.Fill(ds, "Authors");
> MyDataGrid.DataSource= ds.Tables["Authors"].DefaultView;
> MyDataGrid.DataBind();
> }
> since this code correctly agains the pubs db authors table, i

took that
> table and put it in my Database to verify it wasn't a db
issue, that worked
> fine, when took that table and made column name changes, and
data changes -
> nothing. I only get information for 1 person.
>> need help
>> thnx
>>>>>

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: snakeking | last post by:
Hi all, I need to learn enough php to make a 2 page website that looks nice...HELP! SK --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com)....
0
by: James Morrow | last post by:
i need a script for reviewing products (much like epinions.com) written in either perl or php (can't use asp). i am very strapped for time and need a functional script asap, which is why i dont...
6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
5
by: Fred | last post by:
I've check all the info I can find on cookies and I have gotten some idea of how to set a cookie, set the expiration, and get the cookie value. But I need help bringing it all together to...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
10
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
15
by: Jess | last post by:
Hello, Sometimes declarations are all what we need when we define/declare classes (or functions?), but sometimes we need definitions. I learned that if we define a class (B) that has an object...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.