Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Monday, March 26, 2012

How can I capture the id columne from a new datarow?

In my BLL I have a method that adds a new row to a table in the database...

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
public bool AddContact(string firstname, string lastname, string middleinit, bool active, Guid uid, bool newsletter)
{
ContactsDAL.tblContactsDataTable contacts = new ContactsDAL.tblContactsDataTable();
ContactsDAL.tblContactsRow contact = contacts.NewtblContactsRow();

contact.FirstName = firstname;
contact.LastName = lastname;
contact.MiddleName = middleinit;
contact.Active = active;
contact.UserID = uid;
contact.Newletter = newsletter;

contacts.AddtblContactsRow(contact);
int rowsAffected = Adapter.Update(contact);

return rowsAffected == 1;
}

The primary key in this table is a BigInt set as an identity column...How do I capture the value of the primary key that gets created when the new row is added?

Hi,basically the new row that create will be updated with the ID of new inserted record.

However, the following sql piece:

Select SCOPE_IDENTITY()

will do it.

Cheers,

Yani

|||

Im familiar with the idea of SCOPE_IDENTITY but am not certain how to use it in a BLL.

How could I modify the code in my BLL method to retreive the SCOPE_IDENTITY?

|||

Basically, the designer does that for you.

For example the generated Insert statements looks like:

CREATEPROCEDURE [dbo].[AdministratorInsert]

(

@.AdministratorIdint,

@.AdministratorNamenvarchar(50),

@.Passwordnvarchar(50),

@.Activebit

)

AS

SETNOCOUNTOFF;

INSERTINTO [Administrator]([AdministratorId], [AdministratorName], [Password], [Active])VALUES(@.AdministratorId, @.AdministratorName, @.Password, @.Active);

SELECT AdministratorId, AdministratorName, Password, ActiveFROM AdministratorWHERE(AdministratorId= @.AdministratorId)

after a record is inserted , it is selected and the DataRow gots updated automatically.

sql

Wednesday, March 21, 2012

How can I administer SQL Database on remote Web Server

Hello Everybody

Please tell me which is the best method to adminster SQL Server
database in remote web server.

Eg. I am storing all the information of SQL database in my work place
and after that have to upload the modified table to remote web server.
Please tell me what is the easiest way or how I can achieve this
without purchasing third party applications.

With regards

Babu ThomasOn 29 Jul 2003 01:10:50 -0700 in comp.databases.ms-sqlserver,
babu_nir@.hotmail.com (Babu Thomas) wrote:

>Hello Everybody
>Please tell me which is the best method to adminster SQL Server
>database in remote web server.
>Eg. I am storing all the information of SQL database in my work place
>and after that have to upload the modified table to remote web server.
>Please tell me what is the easiest way or how I can achieve this
>without purchasing third party applications.

The easiest way would be to have port 1433 open on the web server and
use EM to manage it. If your web server is VPN enabled use that
otherwise if firewalled you may be able to opne up that port to allow
only your IP address in.

Note, it's not such a good idea to leave this port open to the rest of
the world, it *will* get hacked I promise you, there's no maybes on
this one, it *will* get hacked.

--
Ride Free (but you still have to pay for the petrol)

(replace sithlord with trevor for email)