Database ASP.Net question

Results 1 to 2 of 2

Thread: Database ASP.Net question

  1. #1
    Join Date
    Dec 1969

    Default Database ASP.Net question

    First day on and got the file upload page to work, however, I want to connect to a database and I understand that its not exactly the same as it was in asp 3.0 . <BR><BR>Does anyone have a good example or a good website reference where I could see the code of how it is done? Basicall I need to know how to open the connection to a Microsoft access database that is stored in a database folder in my root directory. then how to build and execute the sql. then close the connection.<BR><BR>any help/references would be greatly appreciated.<BR><BR>Mike

  2. #2
    Join Date
    Dec 1969

    Default RE: Database ASP.Net question

    This was courtesy of Scott Mitchell on this site in an article:<BR><BR>&#039;Create a connection string<BR> Dim connString as String<BR> connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="path odbfile.mdb;"<BR> &#039;Open a connection<BR> Dim objConnection as OleDbConnection = New OleDbConnection(connString)<BR><BR> objConnection.Open()<BR><BR> &#039;Specify the SQL string<BR> Dim strSQL as String = "SELECT first,name FROM students where schcode = &#039;WHS&#039; order by name"<BR><BR> &#039;Create a command object<BR> Dim objCommand as OleDbCommand<BR> objCommand = New OleDbCommand(strSQL, objConnection)<BR><BR> &#039;Get a datareader<BR> Dim objDataReader as OleDbDataReader<BR> objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)<BR><BR> &#039;Do the DataBinding<BR> dgResults.DataSource = objDataReader<BR> dgResults.DataBind()<BR><BR><BR> &#039;Close the datareader/db connection<BR> objDataReader.Close()<BR><BR>for me, dgResults was a datagrid. I&#039;m having trouble getting individual items from the query outside the data grid. Can you help me with that??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts