need help - -PLEASE

M

Mike

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_Connection=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
 
M

Mike

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 said:
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_Connection=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
 
G

Guest

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 said:
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
the users selects a person then clicks the go button
The datagrid should pop with all the information on the selec contac
person, correct 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_Connection=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
 
M

Mike

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 said:
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 said:
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.
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?
(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_Connection=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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top