|
Hi there, Dustin. I would recommend you look at some tutorials to get you started with ASP.NET and database handling. The QuickStart tutorials[^] are a good place to start. In particular, you'll want to read the tutorial "Server-Side Data Access" from the QuickStarts.
You'll start to familiarize yourself with the data objects that you'll need. In a nutshell, you'll find them in the System.Data and System.Data.OleDb namespaces (look for these in the .NET SDK documentation.) You'll use an OleDbConnection object to establish a connection to your access .mdb file. You'll then create an OleDbCommand object to represent your insert statement. Use OleDbParameter objects with the OleDbCommand to apply the values from your textboxes, and use the ExecuteNonQuery method to issue the command to the database. When selecting records you'll likely use a DataSet object or perhaps an OleDataReader
Here is a very raw example of a page that performs an insert to an Access database (in C#):
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Page Language="C#" %>
<script runat="server">
void btnSubmit_Click(object o, EventArgs e)
{
const string kCONNECT_STRING =
"Provider=Microsoft.Jet.OLEDB.4.0; "
+ @"Data Source=c:\inetpub\wwwroot\tests\test.mdb";
const string kINSERT_STATEMENT =
"INSERT INTO [MyTable] ([E-Name], [E-Email]) "
+ " Values (@pName , @pEmail) ";
OleDbConnection con = null;
OleDbCommand cmd = null;
OleDbParameter pName = null;
OleDbParameter pEmail = null;
int insertedID = -1;
try
{
con = new OleDbConnection(kCONNECT_STRING);
con.Open();
cmd = new OleDbCommand(kINSERT_STATEMENT, con);
pName = new OleDbParameter("@pName", DbType.String);
pName.Value = tbName.Text;
cmd.Parameters.Add(pName);
pEmail = new OleDbParameter("@pEmail", DbType.String);
pEmail.Value = tbEmail.Text;
cmd.Parameters.Add(pEmail);
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT @@Identity";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Clear();
insertedID = (int)cmd.ExecuteScalar();
Response.Write(
string.Format("Record has been inserted and assigned ID# {0}."
,insertedID) );
}
catch (Exception x)
{
Response.Write("There has been an error. ");
Response.Write(x.Message);
}
finally
{
if (cmd != null) cmd.Dispose();
if (con != null) con.Dispose();
}
}
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<h3>Insert into Access</h3>
<table>
<tr>
<td>Name</td>
<td><asp:TextBox id="tbName" runat="server" /></td>
</tr>
<tr>
<td>Email</td>
<td><asp:TextBox id="tbEmail" runat="server" /></td>
</tr>
</table>
<asp:Button id="btnSubmit" runat="server" text="Insert"
onClick="btnSubmit_Click" />
</form>
</body>
</html> Another way to go about it is to use the OleDbDataAdapter object - there happens to be a good article on MSDN[^] that discusses how to retrieve the autonumber value after an insert, and their sample code uses OleDbDataAdapter . You may want to go in that direction.
One final word: Access is a good single-user desktop database. It is not as good as other RDBMS (for a variety of reasons) when it comes to multi-user web applications. SQL Server or Oracle may be better choices if you have the $$$. If cost is an issue, you may want to investigate using MSDE - a lighter-weight SQL Server from Microsoft, or perhaps even MySQL.
I hope this helps.
|
|
|
|
|
Thanks -
that is very helpful. I had some code running Select Max(...) type stuff and this seems a bit more robust.
I love CP.
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Hello,
I'm trying to build a database. I'm using ACCESS 2000 to test my queries, but instead of a good start, I'm having a bad one...
When I tried to exucute one of my first queries if faild due to syntax errors. The query looks like this:
CREATE TABLE a
( col_a char(3) not null,
col_b integer not null default('3'),
primary key(col_a),
foreign key(col_b) references b
on delete no action
on update cascade
);
The errors I say that I cant use DEFAULT and ON...
Now is my question: Is my syntax that bad, or do I need a complete DBMS (like SQL server 2000) to execute such advanced queries?
Thanks in advandce
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
Every SQL based engine has slightly different syntax. On the DDL side the syntax differences are even more varied.
You will also find many differences on the syntax for JOINS between TSQL and Access queries.
SQL should expand to 'Suggested Query Language'.
|
|
|
|
|
True, but I looked the syntax up in msdn (even copy/paste the damn code) and it didn't work
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
Try:
http://support.microsoft.com/default.aspx?scid=kb;en-us;180841
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q275561
The syntax is a bit more wordy but, serves its purpose.
|
|
|
|
|
Unfortunately those SQL statements don't work. I guess that I have to test my DBase on a complete DBMS instead of access 2k..
Thanks for your help
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
|
Thanks,
I solved the problem. I did a minimum installation. I figured that the MSDE (Microsoft Database Engine) was needed for the complexe queries.
Everything works fine since I fully installed MS Acces 2k.
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
hi,
why after execution of 'begin transaction' the @@trancount=2(original value is 0)?
thanks!
|
|
|
|
|
When ever a transaction is initiated the @@trancount increases by 1. when a rollback is issued (Even with in nested transaction) the value reset to 0. i am not sure what happens during commit trans (may be it decremented by 1)
Cheers,
Venkatraman Kalyanam
Bangalore - India
Reality bites: I am reality
|
|
|
|
|
yes,commit trans decremented by 1,but after this command ,the @@trancount is
1,not 0,the problem is what makes the strange,the @@trancount incremented by 2?
|
|
|
|
|
william_zhou wrote:
the problem is what makes the strange,the @@trancount incremented by 2?
Do you work in Implicit Transactions mode which may be causing this effect ?
|
|
|
|
|
no,i assure i had not used this mode
|
|
|
|
|
oh,i'm sorry,
i did work in Implicit Transactions mode,but this mode was not setted by me,
now how can i cancel this mode
|
|
|
|
|
SET IMPLICIT_TRANSACTIONS OFF
good luck
|
|
|
|
|
thanks,
but a new problem appears,when i call this proc in my embeded c sql,the return
value is -266,which is the same problem @@trancount,i am nearly insane for this bad luck,why?
|
|
|
|
|
i set implicit_transactions off at the beginning of the proc,such as:
'alter proc sp_myproc @i_input
as
set implicit_transactions
declare @tmp int
...
'
but when i debug it,i find behind the 'set implicit_transactions' is a strange
message:'set implicit_transactions on',now who active this event,why can it happen?
|
|
|
|
|
use SET IMPLICIT_TRANSACTIONS OFF before beginning any transactions not inside a transaction.
then start the transaction explicitly using BEGIN TRAN
|
|
|
|
|
I have a Linux server, with Samba, running MySQL.
I need to access this from a Windows 2000 machine.
What is the best way to do this with MFC/C++ ?
|
|
|
|
|
I thought MySQL had a c++ client class for this (even a 'c' one would do) - in which case you would link it into your code, make a connection with the class 'across the network' to the MySQL server, presto !!!!
the other option would be to see if there's an ODBC driver for MySQL on Linux
'G'
|
|
|
|
|
I send @DD(a date) to the procedure and I want to get only the TesterIDs that have a ScheduleStamp(a date)on or before @DD. Each person(designated by TesterID) can have multiple ScheduleStamps, I only want to see the person if their ScheduleStamps exists on or before @DD, but I don't want to see them if they have a ScheduleStamp before and after @DD.
I know it may sound confusing, but thank you to anyone who takes on this challenge.
CREATE PROCEDURE usp_tp_GetPKCall
@SexID char,
@RaceID char,
@LBirth datetime,
@UBirth datetime,
@SiteID varchar(5),
@DD datetime
AS
if @SexID = '*' and @RaceID <> '*' and @SiteID <> '90000'
SELECT tGroup.ScheduleStamp, tResultQue.TesterID, tTester.LastName,tTester.FirstName, tTester.WorkNo, tTester.WorkExtension, tTester.HomeNo,tTester.SexID, tTester.Birth, tTester.RaceID, tTester.SiteID
FROM tGroup INNER JOIN
tResultQue ON tGroup.GroupID = tResultQue.GroupID INNER JOIN
tTester ON tResultQue.TesterID = tTester.TesterID
where tTester.RaceID = @RaceID and tTester.Birth >= @LBirth and tTester.Birth <= @UBirth and tTester.SiteID = @SiteID and tGroup.ScheduleStamp >= @DD
GO
|
|
|
|
|
(1) Your logic does not make sense:
- I only want to see the person if their ScheduleStamps exists on or before @DD
- I don't want to see them if they have a ScheduleStamp before and after @DD
I think you only want people who do not have a ScheduleStamp prior to @DD
(2) Find the people who have a schedule stamp prior to @DD
<br />
SELECT tTester.TesterID<br />
FROM tTester<br />
INNER JOIN tResultQue<br />
ON (tTester.TesterID = tResultQue.TesterID)<br />
INNER JOIN tGroup<br />
ON (tResultQue.GroupID = tGroup.GroupID)<br />
WHERE tGroup.ScheduleStamp < @DD<br />
GROUP BY tTester.TesterID<br />
(3) Add it to the WHERE clause
<br />
AND tTester.TesterID NOT IN <br />
(SELECT tTester.TesterID<br />
FROM tTester<br />
INNER JOIN tResultQue<br />
ON (tTester.TesterID = tResultQue.TesterID)<br />
INNER JOIN tGroup<br />
ON (tResultQue.GroupID = tGroup.GroupID)<br />
WHERE tGroup.ScheduleStamp < @DD<br />
GROUP BY tTester.TesterID)<br />
|
|
|
|
|
That's half of it. The problem is, each person can be listed in the table multiple times because they may have multiple ScheduleStamps. I do want to see the person if ScheduleStamp <= @DD, but if they also have one > @DD, I don't want to see them at all.
Thanks again
|
|
|
|
|
That's half of it. The problem is, each person can be listed in the table multiple times because they may have multiple ScheduleStamps. I do want to see the person if ScheduleStamp <= @DD, but if they also have one > @DD, I don't want to see them at all.
Thanks again
P.S. using SQL Server
|
|
|
|