473,732 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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'colum n 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 1728
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(SqlDataRe ader dr = cmd.ExcuteReade r(CommandBehvio ur.CloseConnect ion)
{
while(dr.Read() )
{
ddl1.Items.Add( new ListItem(dr.Get String(0),dr.Ge tInt32(1)))
}
dr.Close();
}
"thebison" <al************ @btinternet.com > wrote in message
news:11******** *************@g 10g2000cwb.goog legroups.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'colum n 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....pe rhaps 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 "Redistribu tion 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.sqlDataAda pter1.Fill(this .dsProjectName1 );
ddProjectName.D ataBind();
this.sqlDataAda pter3.Fill(this .dsTaskName1);
ddTaskName.Data Bind();
this.sqlDataAda pter4.Fill(this .dsResourceFull Name1);
ddResName.DataB ind();
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 SelectIndexChan ged 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
SelectedIndexCh anged 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.RowFi lter = "Task.Proje ctID =
(ddProjects.Sel ectedValue) ";

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.Tab les[0].DefaultView;
ddTaskName.Data Source = dv;
ddTaskName.Data TextField = ..
.......
dataView3.RowFi lter = "Task.Proje ctID =" + ddProjects.Sele ctedValue
ddTaskName.Data bind();

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.goo glegroups.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
SelectedIndexCh anged 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.RowFi lter = "Task.Proje ctID =
(ddProjects.Sel ectedValue) ";

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 DataTextFormatS tring 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 DataTextFormatS tring 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.goo glegroups.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 DataTextFormatS tring 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 DataTextFormatS tring 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
3225
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 lost when they move to a new record. This seems to be the case when there are multiple users. When there is a single user using it, we don't seem to have that problem. It seems that we had this problem when we first converted from an MDB back end...
2
2033
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. I've set the Record Source to both the query, and the SQL contained within the query, and although the system pauses long enough to have gone out and retrieved the data, I can't see it. The form itself remains gray. In addition: ...
3
1726
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. http://www.datastuff.com/cgi-bin/ocs?Lo=yourname&Rpt=703&Month=7-5&Select=CC this is posted back to us as a file called data. There is no extension to is so the first thing that IE does is ask to save and where.
1
2586
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 looking for a robust solution for a major application. Almost every developer seems to come up with a completely different solution. While many of them are not bad, I really want a very good one. My database is SQL Server 2000 and I am using Visual...
15
2560
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, modifications and deletions functions very well in the dataset. But impossible to transmit modifications in ACCESS database. Impossible to WRITE in database. Here is the code for data transmission from tableadapter to Access database :
5
5323
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 single repository. Currently, it is semi-automated i.e. we are using MS Excel for data entry, consolidation and report generation (i.e. using formulas). We require a tool that will provide: a) A web-based interface for data entry (i.e. remote,
0
14420
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 be greater than 255 characters. 2. I have an access database. I link (not import) to the contents of the excel spreadsheet. In the design view in access, Column A has the data type "memo".
11
2575
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
3045
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 padded with a bunch of null characters at the end.
6
2420
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 connection string works fine and the tables are added to the project without a problem. When I create the tables they appear to bind and I am able to preview the data in the database in design mode; however, at runtime no data is displayed and the...
0
8946
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, 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...
0
8774
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,...
0
9181
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 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...
0
8186
agi2029
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...
1
6735
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 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...
0
6031
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();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
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...

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.