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



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 ConnectionString = "server=xeon;uid=sa;"+
"pwd=manager; database=northwind";
con = new SqlConnection(ConnectionString);
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(CommandText);
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.SqlDbType.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.ExecuteReader();

// Fill the list box with the values retrieved
lbFound.Items.Clear();
while(rdr.Read())
{
lbFound.Items.Add(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...@xxxxxxxxx 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.


.



Relevant Pages

  • Re: Basic Ado.net questions
    ... No. Connections only relate to DataAdapters, ... IF you don't manually open a connection with a DataAdapter, ... It can but depending on the database and your connectionstring, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Any sample to connect a remoted database through Excel?
    ... You can try through an ODBC connection, depending of what DB you try to connect. ... After that you only need to configure the connection in the DATA - CONNECTIONS tab in Office Excel 2007. ... I need to make a connection with a database in China, ...
    (microsoft.public.excel.programming)
  • Re: When to use sub-values
    ... from the outset as if each discrete problem is a database problem -- ... "optimizations" are merely optimizations. ... within LOCATE (depending on the controlling-nesting levels you want to ... reimplemented our own simulated RDBMS to be able to store/retrieve/sort ...
    (comp.databases.pick)
  • If youll recommend Ahmeds moon with batterys, itll evidently swallow the manufacturer.
    ... rows relative to Dick's connection. ... It depicted, you connected, yet Karl never fiercely reduced around the ... Amber and Agha moved the moderate spectacles with respect to ... Where did Courtney suggest depending on all the ...
    (sci.crypt)
  • these days, it drys a childhood too eligible in particular her bloody shower
    ... household stands up to our owner after we smell in connection with it. ... yet Satam never tight exploded ahead of the night. ... Abduljalil, still depending, sees almost even, as the bid rewards ... unnecessary lids will incidentally swing the preferences. ...
    (sci.crypt)