473,399 Members | 4,192 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,399 software developers and data experts.

ASP.NET Data Access Problem

Hi all,

I hope someone can help with this relatively simple problem.
I am building a timesheet application using ASP.NET C# with Visual
Studio 2003.As it is only a protoype application, my database has been
made in MSDE.

As part of my application, I have a 'Resources' table, which holds
employee information. I have the fields FirstName and LastName which
are entered in my data capture form which works fine. The problem
however, is that on other forms, for example, I wish to be able to
select employees from a drop-down list which shows both their first and

last names. At present my drop-down lists can only showHow should I go
about this? Can I create a view or something to achieve this? Or could
I insert a 'FullName'column into my 'Resources' table, which is set by
default to take the first and last names of each new resource and
concatanate it into one string? I worked on an application previously,
which seemed to do something similar, although I don't know how.

What I did try originally was to show the resource information on the
form as a DataGrid, but was unable to successfully pass the
SelectedItem when my 'submit' button was pressed.

Any thoughts, suggestions would be much appreciated!

Thanks again

Al

Apr 5 '06 #1
9 1711
If you have an employee class, you can add a FullName get property, and
then databind to that. You can even get clever and have a FormatName
method which returns names as Surname, Firstname; Firstname Surname;
etc.

public class Employee
{
public string FirstName
{
get {}
set {}
}

public string Surname
{
get {}
set {}
}

public string FullName
{
get { return string.Format("{0} {1}", FirstName, Surname); }
}
}

Apr 5 '06 #2
If I undertand your Question right.. this is simply done in your query
"Select ID, Firstname+' '+LastName AS FullName From Employees";

in your code you may use reader or dataset, For me i use datareader.
using(SqlDataReader dr = cmd.ExcuteReader(CommandBehviour.CloseConnection)
{
while(dr.Read())
{
ddl1.Items.Add(new ListItem(dr.GetString(0),dr.GetInt32(1)))
}
dr.Close();
}
"thebison" <al************@btinternet.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
Hi all,

I hope someone can help with this relatively simple problem.
I am building a timesheet application using ASP.NET C# with Visual
Studio 2003.As it is only a protoype application, my database has been
made in MSDE.

As part of my application, I have a 'Resources' table, which holds
employee information. I have the fields FirstName and LastName which
are entered in my data capture form which works fine. The problem
however, is that on other forms, for example, I wish to be able to
select employees from a drop-down list which shows both their first and

last names. At present my drop-down lists can only showHow should I go
about this? Can I create a view or something to achieve this? Or could
I insert a 'FullName'column into my 'Resources' table, which is set by
default to take the first and last names of each new resource and
concatanate it into one string? I worked on an application previously,
which seemed to do something similar, although I don't know how.

What I did try originally was to show the resource information on the
form as a DataGrid, but was unable to successfully pass the
SelectedItem when my 'submit' button was pressed.

Any thoughts, suggestions would be much appreciated!

Thanks again

Al

Apr 5 '06 #3
Hi everyone!

Thanks, that is exactly what I wanted. My drop-down list now shows the
FullName and it looks great!

While I have your attention....perhaps any of you could assist with
another issue I am having on the same form. The basic point of this
form is to assign a Resource (Employee) onto a Task, which has
previously been assigned to a Project. The way I have laid the form out
is that you can select Projects, Tasks, and Employees all from
drop-down lists. The user can then add some dates, and click submit to
send it to the database.

My problem is that I want the Task drop-down list to automatically
repopulate with the correct tasks when the user selects a Project from
the Project drop-down. What I mean by this is that if for example the
user selects "Redistribution Project" from the list, then only tasks
from that Project will be available in the Tasks drop-down.

I believe I will have to do something with my page_load, specifically
the IsPostBack part...but I am not sure exactly. My code is currently:

if(!IsPostBack)
{
this.sqlDataAdapter1.Fill(this.dsProjectName1);
ddProjectName.DataBind();
this.sqlDataAdapter3.Fill(this.dsTaskName1);
ddTaskName.DataBind();
this.sqlDataAdapter4.Fill(this.dsResourceFullName1 );
ddResName.DataBind();
sqlConnection1.Close();
}

Any help greatly appreciated!

Thanks

Al

Apr 5 '06 #4
Well initially you have to load you Projects in the dropdown list so
that should go in the !IsPostBack. However, the other two are loaded
on demand when a user select a project. So, Your dropdown list for
your project should have autopostback = true. Then,
you must load the TaskName items in the SelectIndexChanged event for
the ddProjectname using the value for the dropdown list of the
projectnames as the filter criteria. The same goes if you want to load
the ResourceName ddl on demand.

Apr 5 '06 #5
Hi again,

Thanks for your help, I have managed to put the relevant ddls in the
right place so that they are posting back at the right time (using the
SelectedIndexChanged part of the code). However I cannot quite get my
RowFilter to work. I'm not sure exactly what I should be putting in
there.

Basically I am populating the Task drop-down list with a DataView. So I
need a RowFilter for the Tasks that filters the TaskID to only show
those that have the same ProjectID as selected from the Project
Drop-Down List.

Something like... dataView3.RowFilter = "Task.ProjectID =
(ddProjects.SelectedValue) ";

The ddProjects is passing the ProjectID as its DataValueField.

Any help appreciated, as ever!

Thanks

Al

Apr 5 '06 #6
The code you wrote for filtering is ok.
I can see that you bind your dropdownlists visually, and generate typed
dataset.. and also the views..
Here is the the code i may use:

DataView dv = dsTaskName1.Tables[0].DefaultView;
ddTaskName.DataSource = dv;
ddTaskName.DataTextField = ..
.......
dataView3.RowFilter = "Task.ProjectID =" + ddProjects.SelectedValue
ddTaskName.Databind();

this will work.. give it a try..

PS... check this usefull link
http://msdn.microsoft.com/practices/...s/default.aspx

"thebison" <al************@btinternet.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
Hi again,

Thanks for your help, I have managed to put the relevant ddls in the
right place so that they are posting back at the right time (using the
SelectedIndexChanged part of the code). However I cannot quite get my
RowFilter to work. I'm not sure exactly what I should be putting in
there.

Basically I am populating the Task drop-down list with a DataView. So I
need a RowFilter for the Tasks that filters the TaskID to only show
those that have the same ProjectID as selected from the Project
Drop-Down List.

Something like... dataView3.RowFilter = "Task.ProjectID =
(ddProjects.SelectedValue) ";

The ddProjects is passing the ProjectID as its DataValueField.

Any help appreciated, as ever!

Thanks

Al

Apr 6 '06 #7
Hi,
Thanks, I have this working now! :-)

I now have another question, I've searched all over the web for the
answer, but can't quite work it out. I am filling a list-box with
'Start Date' and 'Finish Date' from a table, and have concatanated
these into a new field, 'Full Date'. However when I DataBind the
list-box it shows the format as '01/10/06 12:00:00 - 07/10/06
12:00:00'. I do not want the times to show. I know how to format one
column, using the DataTextFormatString property, setting it to {0:d} ,
but I can't work out what it will need to be for my 'Full Date' field.

The actual data expression for 'Full Date' is
StartDate + '-' + FinishDate

And I wish it to show in the ListBox as '01/10/06 - 07/10/06'.
Anyone have any ideas on what I should put into DataTextFormatString to
achieve this?

Many Thanks!

Al

Apr 8 '06 #8
this artcile should help
http://www.codeguru.com/csharp/cshar...cle.php/c4205/

Also i think try formatting the date values before adding it to your listbox
do it in the code behind or try looking at string.Format
Patrick

"thebison" <al************@btinternet.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Hi,
Thanks, I have this working now! :-)

I now have another question, I've searched all over the web for the
answer, but can't quite work it out. I am filling a list-box with
'Start Date' and 'Finish Date' from a table, and have concatanated
these into a new field, 'Full Date'. However when I DataBind the
list-box it shows the format as '01/10/06 12:00:00 - 07/10/06
12:00:00'. I do not want the times to show. I know how to format one
column, using the DataTextFormatString property, setting it to {0:d} ,
but I can't work out what it will need to be for my 'Full Date' field.

The actual data expression for 'Full Date' is
StartDate + '-' + FinishDate

And I wish it to show in the ListBox as '01/10/06 - 07/10/06'.
Anyone have any ideas on what I should put into DataTextFormatString to
achieve this?

Many Thanks!

Al

Apr 9 '06 #9
Hi,
Thanks for your reply. I think the reason I am having a problem is that
my 'FullDate' column is being defined as a string, made up of
"StartDate and FinishDate', as shown below:

StartDate + '-' + FinishDate

This means that if it is a string, applying Date Formatting such as
{0:d} (as in the article you suggested) does nothing. When I set the
data type of 'FullDate' to be DateTime, I get the following error

'Cannot convert value '13/03/2006 00:00:00- 19/03/2006 00:00:00' to
Type: System.DateTime.'

So what I am trying to do is cast a string into a DateTime column,
which won't work, obviously. Is there any other way I can accomplish
this?

Many thanks

Al

Apr 9 '06 #10

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

Similar topics

32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
2
by: David C. Barber | last post by:
upsized an MDB to ADP/SQL Server 2000 under Access 2000. All the DAO code that I've changed to ADO code is working fine, HOWEVER the form Record Source itself does not seem willing to return data....
3
by: sparks | last post by:
They have a new data collection station. The people here are using access 97.... This third party site will only post data back to us when we do this. ...
1
by: Johann Blake | last post by:
I am looking for a good solution on how to implement data access in an application so that there is a clean separation between the data access layer, the business layer and the GUI layer. I am...
15
by: philip | last post by:
On a form, I have a datagridview. This datagridview is constructed on a dataset filled by a tableadapter. The table adapter do very well what it must do when filling dataset. Insertions,...
5
by: SRAM | last post by:
Hi, Problem statement: We have some amount of data stored in various excel sheets and we generate a few reports from these data. We are in the process of consolidating all data to reside in a...
0
by: Grip | last post by:
Hi, I have gone throught the group and Microsoft's online help and have seen many suggestions but I am still seeking clarity: 1. I have an excel spreadsheet. Column A contains text that may...
11
by: Chad | last post by:
Hi Is it possible to substitute an alternative data source (eg MySQL or SQL Server) into an existing MS-Access application?
3
by: Joe Salmeri | last post by:
I have found a data corruption problem with pyodbc. OS = Windows XP SP2 DB = Microsoft Access XP PROBLEM: When selecting columns from a table that are of type Memo the value returned is...
6
by: Wesley Peace | last post by:
I hate to cross post, but I've gotten no answer yet on a problem I'm having with visual studio 2008. I've created a series of forms with controls to access a Access database tables. The...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
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...
0
isladogs
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...

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.