[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

John Fabiani

4/9/2002 4:27:00 PM

Hi,
According to everything I've read there is no locking rows available with C#
and ADO.NET. OK so how does everyone deal with PK's? What I did in the
past was use a table that had my PK field. I locked the table and then
updated the field by one for my new PK. But locking is no longer supported.
So how do I create and use PK's?
John


2 Answers

(Steven Bras [MS])

4/9/2002 9:57:00 PM

0

John Fabiani

4/9/2002 10:24:00 PM

0

I took your adviuce and decided that I would still attempt to use VFP
functions instead of GUID's.
It took a while to find information but I re-read chapter 5 of "What's New
in VFP 7" which discussed the new OLE DB provider than I'm using to connect
to a VFP database. It supports many of the VFP functions. So the code
below works. However, I am attempting to figure out is it better to use a
return value (the PK) from a procedure then passing the value to the
standard Ado.net update and add routines. Or is attempting to use the stored
procedure from the insert (by inserting it into the call into the command
text) better? At the moment I don't completely understand the way
oleDbInsertCommand1 works but I'm reading.


private void insertbutton_Click(object sender, System.EventArgs e)
{
oleDbConnection1.Open();
//serialnumber() is a stored procedure written by a member of the UT Hilmar
Zonneveld
//serialnumber('esagency')
string sqlSelect = "INSERT INTO mytest (agencyid,name)VALUES
(serialnumber('esagency'),'test')";

System.Data.OleDb.OleDbCommand mysqlcmd = new
System.Data.OleDb.OleDbCommand(sqlSelect,oleDbConnection1);

mysqlcmd.ExecuteNonQuery();
oleDbConnection1.Close();
}
Thanks for all the help and suggestions.
John

"Steven Bras [MS]" <stevenbr@online.microsoft.com> wrote in message
news:FEZ4kCA4BHA.2184@cpmsftngxa08...
> You are correct; ADO.Net does not support locking because it's essentially
> a disconnected data access model.
>
> You might wish to look at what your database has to offer in that regard;
> if you're using Access, you can define a column as autonumber; in SQL
> Server, you can set a column as an "identity" column which gives you an
> autoincrementing field value. Since you don't post what database you are
> using, it's difficult to determine if this will be an option.
>
> Hope this helps.
>
> Steven Bras, MCSD
> Microsoft Developer Support/Visual Basic WebData
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
> Are you secure? For information about the Microsoft Strategic Technology
> Protection Program and to order your FREE Security Tool Kit, please visit
> http://www.microsoft.co....