473,835 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp.net, vs2k5, getting started connecting to databases... I'm confused

I've been programming a bit in PHP and then recently learnt classic
ASP for projects at work, now I'm working on another project that they
want done in .net. I've got my head around web parts, that wasnt as
complicated as I thought it would be.

Now I want to create a web part, that connects and uses our database
to show data depending on what user it is.

I know theres the dataview controls and all that, but I dont want to
display all the data, I just want to have the data in a recordset like
you could in classic so then I can manipulate it and display it how I
want.

Can you even do that anymore, Ive been reading guides but they all
talk about data acess layers which seem like more complication than I
need.

Can anyone point me in the right direction, or link to a good simple
guide on doing such a thing, I'm really confused.

Mar 22 '07 #1
3 1614
Welcome and forget about PHP! :)

It's a bit confusing when you first get started and the short answer
is yes.

Depending on how you want to display the data in your webparts, say
retrieve a list of users into a dropdown box, you can do your magic in
sql, use our data ADO.NET classes such as "DataReader ", "DataSet" or
"DataTable" , you can bind your results to them. A quick example using
sqlserver

SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;

try
{
// Open connection to the database
string ConnectionStrin g = "server=xeon;ui d=sa;"+
"pwd=manage r; database=northw ind";
con = new SqlConnection(C onnectionString );
con.Open();

// Set up a command with the given query and associate
// this with the current connection.
string CommandText = "SELECT FirstName, LastName" +
" FROM Employees" +
" WHERE (LastName LIKE @Find)";
cmd = new SqlCommand(Comm andText);
cmd.Connection = con;

// Add LastName to the above defined paramter @Find
cmd.Parameters. Add(
new SqlParameter(
"@Find", // The name of the parameter to map
System.Data.Sql DbType.NVarChar , // SqlDbType
values
20, // The width of the parameter
"LastName") ); // The name of the source column

// Fill the parameter with the value retrieved
// from the text field
cmd.Parameters["@Find"].Value = txtFind.Text;

// Execute the query
rdr = cmd.ExecuteRead er();

// Fill the list box with the values retrieved
lbFound.Items.C lear();
while(rdr.Read( ))
{
lbFound.Items.A dd(rdr["FirstName"].ToString() +
" " + rdr["LastName"].ToString());
}
}
catch(Exception ex)
{
// Print error message
MessageBox.Show (ex.Message);
}
finally
{
// Close data reader object and database connection
if (rdr != null)
rdr.Close();

if (con.State == ConnectionState .Open)
con.Close();
}
txtFind.Text is a textbox value on the page and lbFound is the
dropdownlist name.

Example taken from http://www.akadia.com/services/dotnet_data_reader.html

Hope that helps.

Liming Xu
Jumptree Project Management
www.jumptree.com

On Mar 21, 9:52 pm, itfet...@gmail. com wrote:
I've been programming a bit in PHP and then recently learnt classic
ASP for projects at work, now I'm working on another project that they
want done in .net. I've got my head around web parts, that wasnt as
complicated as I thought it would be.

Now I want to create a web part, that connects and uses our database
to show data depending on what user it is.

I know theres the dataview controls and all that, but I dont want to
display all the data, I just want to have the data in a recordset like
you could in classic so then I can manipulate it and display it how I
want.

Can you even do that anymore, Ive been reading guides but they all
talk about data acess layers which seem like more complication than I
need.

Can anyone point me in the right direction, or link to a good simple
guide on doing such a thing, I'm really confused.

Mar 22 '07 #2
Thanks!

I think I have that sorted, Im getting data from my database and can
play with it like I want to.

The only thing is, Im doing that in the controls .cs file (the code
file), which is all well and good, but I want to just use some of it
in tables and as parts of hyperlinks on my web parts main display. How
to I share the data from my code file, onto the main display so I can
do normal ASP coding instead of just straight c sharp.
What I mean is, at the moment in my mainjobs.ascx.c s file I have

protected void Page_Load(objec t sender, EventArgs e)
{
SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;

try
{
string ConnectionStrin g =
"server=NEWK;ui d=infobase;pass word=sdfsdf; database=Infoba se";
con = new SqlConnection(C onnectionString );
con.Open();

string CommandText = "Select StaffID, ProjectNumber" +
" FROM Project_Staff" +
" WHERE (StaffID = 187)" +
" ORDER BY ProjectNumber";
cmd = new SqlCommand(Comm andText);
cmd.Connection = con;

rdr = cmd.ExecuteRead er();
ArrayList rowList = new ArrayList();
while (rdr.Read())
{
object[] values = new object[rdr.FieldCount];
rdr.GetValues(v alues);
rowList.Add(val ues);

lblJobs.Text += rdr["ProjectNum ber"].ToString() +
"<br>";
}

}
catch (Exception ex)
{
Response.Write( "fail");
}
finally
{
if (rdr != null)
rdr.Close();

if (con.State == ConnectionState .Open) ;
con.Close();
}

}

what I want to do is do a loop and write some values to a table, in
hyperlinks etc on my normal mainjobs.ascx(o r I could even start an
aspx file and use iframes) - how do I get the values from one to the
other?

I want to be able to do a while loop that creates table cells and
hyperlinks and so forth for the rdr["ProjectNum ber"] variables.

Mar 22 '07 #3
If you want rows and columns, bind the data to a GridView in 2.0, a DataGrid
in 1.1

If you want more fine tuned control, look at the Repeater object.

As in

<asp:repeater ......

http://www.asp101.com/articles/john/...er/default.asp
(this article is for 1.1, but you can learn from it)
http://www.gridviewguy.com/CategoryD...x?categoryID=7
<it******@gmail .comwrote in message
news:11******** ************@o5 g2000hsb.google groups.com...
I've been programming a bit in PHP and then recently learnt classic
ASP for projects at work, now I'm working on another project that they
want done in .net. I've got my head around web parts, that wasnt as
complicated as I thought it would be.

Now I want to create a web part, that connects and uses our database
to show data depending on what user it is.

I know theres the dataview controls and all that, but I dont want to
display all the data, I just want to have the data in a recordset like
you could in classic so then I can manipulate it and display it how I
want.

Can you even do that anymore, Ive been reading guides but they all
talk about data acess layers which seem like more complication than I
need.

Can anyone point me in the right direction, or link to a good simple
guide on doing such a thing, I'm really confused.

Mar 22 '07 #4

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

Similar topics

2
1632
by: Steve Gollery | last post by:
I installed Postgres 8 beta 3 on an XP box, with Postgres running as a service. TaskManager tells me that postgres and postmaster are both running. Using pgAdmin III, I can connect to the server and create users, databases, tables, etc. But at the command line, on the same machine where the service is running, executing createdb mydb
3
2641
by: Chris | last post by:
Don't know if there is a simple solution for this one or not. When running SQL server on a machine with 2000 loaded and the complete SQL package I don't have any issues. Now I'm trying to login using my XP machine with MSSQL developer edition, and I can not connect to my remote servers via TCP/IP. It can see the server, and it establishes a connection, but I can't access my files, and the connection seems incredibly slow. I have checked my...
0
1233
by: Quantum | last post by:
Hi there, I've got a VS2K5 project in the folder: c:\BigProject\Windows\ However, I've got all the source in this folder: c:\BigProject\Independent\
5
2487
by: Odd Bjørn Andersen | last post by:
I have installed DB2 9 Enterprise Edition on my laptop and created the sample database. Now I'm having truble connecting to the database from Command Editor. If I connect from Command Window it's no problem connecting to sample (or any other databases - local or remote), but if I try to connect from Command Editor I'm not able to do that. There is no error message, the Progress dialog just run and run without anything happening. Is this...
4
1478
by: SteveW | last post by:
Now that vista and the 3.0 framework are gold, I'm a bit confused, so any clarification would be very helpful. The 3.0 framework is gold and is downloadable etc. What is not 'gold' and 'supported' is the WCF/WPF addons to vs2k5. But here's where I get confused. If I have vs2k5 source code. which contains 3.0 'code', on a pc which does not have the WCF/WPF addons. It compiles, runs, has intellisense etc. etc. etc.
3
1595
by: =?Utf-8?B?QWRpbCBBa3JhbQ==?= | last post by:
I posted this question in vsnet.ide newsgroup about more than a week back but didn't get any single response yet therefore, reposting again same to several newsgroups. When I run my C# WinForms project either by pressing F5 or clicking Start button on toolbar, it sometimes doesn't execute the currently changed code and runs previously compiled code and this strange thing happens occasionally no matter its started in Debug or Release...
3
6008
by: ist | last post by:
Hi, I am trying to get (and transfer over ASP.NET) some encrypted data from some MySQL fields. Since the data contains many unicode characters, I tried to get the data as a series of ASCII values, transfer those numeric values over ASP.NET. I had no problem doing this on my local computer, by getting the field with "cast(field as BINARY)" so that on ASP.NET I have a byte array.Then send every field of array over ASP.Net.
0
1562
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the databases in that server. Then after the user selects a database, I have another button that he/she click and I want to retrieve file groups from a specific table. At this point when he/she clicks on that button I get an error:
30
2983
by: iheartvba | last post by:
Hi, I already have 3 Databases running: A. they all have the same tables and the same structure B. There is no 1 Master table they are all separate tables What I want to do is to merge them into 1 Master Table to be able to generate reports etc. An append query will not suffice because some fields get updated in the orginial databases. I have looked into database replication and I think it would work. I have considered the following...
0
9802
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
9652
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
10517
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10559
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,...
0
10230
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
6961
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
5802
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3990
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.