Click here to Skip to main content
15,899,313 members
Home / Discussions / Database
   

Database

 
QuestionA Question About Architecture Pin
Roger Wright21-Jan-10 18:02
professionalRoger Wright21-Jan-10 18:02 
AnswerRe: A Question About Architecture Pin
Mycroft Holmes21-Jan-10 21:45
professionalMycroft Holmes21-Jan-10 21:45 
GeneralRe: A Question About Architecture Pin
Roger Wright22-Jan-10 19:41
professionalRoger Wright22-Jan-10 19:41 
GeneralRe: A Question About Architecture Pin
Mycroft Holmes22-Jan-10 20:37
professionalMycroft Holmes22-Jan-10 20:37 
GeneralRe: A Question About Architecture Pin
Roger Wright22-Jan-10 21:00
professionalRoger Wright22-Jan-10 21:00 
QuestionSQL Server Agent not displayed in Object Explorer in SQL Server 2005 Express Edition Pin
tannghia21-Jan-10 16:13
tannghia21-Jan-10 16:13 
AnswerRe: SQL Server Agent not displayed in Object Explorer in SQL Server 2005 Express Edition Pin
Eddy Vluggen22-Jan-10 0:11
professionalEddy Vluggen22-Jan-10 0:11 
Questionout parameters workaround for Ms Access [solved] [modified] Pin
Dan Mos21-Jan-10 10:28
Dan Mos21-Jan-10 10:28 
Hy,

I've got a really unpleasant task.
To create a personnel tracking app using MS Access as the "DB provider".

Here's my problem:

I have a table named Person

Person
=========
ID - AutoNumber
Name - Text(40)
Adress - Text(50)
.
.
.

I have some "stored procs"/querys.
//this one adds a person(actually not this one but similar with extra fields)
PARAMETERS inName Text ( 255 ), inAdress Text ( 255 );//more but let's simplify
INSERT INTO Person( Name, Adress )
VALUES(inName, inAdress);

//something like this gets the ID
PARAMETERS inName Text ( 255 ), inAdress Text ( 255 );
SELECT Person.ID
FROM Person
WHERE (Person.Name= [inName]) AND (Person.Adress= [inAdress]);


And here is a mini version of one of the calsses:

 public class Person : IComparable<Person>
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Adress { get; set; }

        public int CompareTo(Person other)
        {
            int equality = this.Name.CompareTo(other.Name);
            if (equality < 0) return -1;
            else if (equality == 0)
            {
                return this.Adress.CompareTo(other.Adress);
            }
            else
            {
                return 1;
            }
        }
    }


//and here is the code that inserts the Person and then gets the ID

int id = 0;
            try
            {
                con.Open();
                //insert the person
                OleDbCommand cmd = new OleDbCommand();
                cmd.CommandText = "EXEC procAddPerson";
                int result = cmd.ExecuteNonQuery();

                if (result == 1)
                {
                    //get the ID by changing the comand text to execute the GetID query
                    cmd.CommandText = "EXECUTE procGetPersonID";
                    id = Convert.ToInt32(cmd.ExecuteScalar());
                }
            }
            catch
            {
                id = -1;
                //log and stuff
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
                con = null;
            }

            return id;


And here is my question:
I know that Access/JET does not support out params but is there a better/faster way of getting the ID or any auto generated numbers?

Thanks in advance.

===========
EDIT:
===========
heres the working code(A lot fatser then searching for a match and return/select the ID):
con.Open();
//insert the person
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "EXEC procAddPerson";
int result = cmd.ExecuteNonQuery();

if (result == 1)
{
    //get the ID by changing the comand text
    cmd.CommandText = "Select @@Identity";
    id = Convert.ToInt32(cmd.ExecuteScalar());
}


modified on Friday, January 22, 2010 12:10 PM

AnswerRe: out parameters workaround for Ms Access Pin
Mycroft Holmes21-Jan-10 12:05
professionalMycroft Holmes21-Jan-10 12:05 
GeneralRe: out parameters workaround for Ms Access Pin
Dan Mos22-Jan-10 3:13
Dan Mos22-Jan-10 3:13 
AnswerRe: out parameters workaround for Ms Access Pin
Pranay Rana21-Jan-10 17:51
professionalPranay Rana21-Jan-10 17:51 
GeneralRe: out parameters workaround for Ms Access Pin
Dan Mos22-Jan-10 3:09
Dan Mos22-Jan-10 3:09 
QuestionComposite primary key Table Insertion Problem in SQL Pin
vishnukamath20-Jan-10 22:37
vishnukamath20-Jan-10 22:37 
AnswerRe: Composite primary key Table Insertion Problem in SQL Pin
Bassam Saoud22-Jan-10 5:03
Bassam Saoud22-Jan-10 5:03 
Questionselecting first 7 days from database Pin
benjamin yap20-Jan-10 18:02
benjamin yap20-Jan-10 18:02 
AnswerRe: selecting first 7 days from database Pin
Luc Pattyn20-Jan-10 18:12
sitebuilderLuc Pattyn20-Jan-10 18:12 
AnswerRe: selecting first 7 days from database Pin
Mycroft Holmes20-Jan-10 18:32
professionalMycroft Holmes20-Jan-10 18:32 
GeneralRe: selecting first 7 days from database Pin
David Skelly20-Jan-10 22:49
David Skelly20-Jan-10 22:49 
GeneralRe: selecting first 7 days from database Pin
Mycroft Holmes20-Jan-10 23:27
professionalMycroft Holmes20-Jan-10 23:27 
GeneralRe: selecting first 7 days from database Pin
David Skelly21-Jan-10 1:48
David Skelly21-Jan-10 1:48 
GeneralRe: selecting first 7 days from database Pin
Mycroft Holmes21-Jan-10 11:58
professionalMycroft Holmes21-Jan-10 11:58 
AnswerRe: selecting first 7 days from database Pin
David Skelly20-Jan-10 22:44
David Skelly20-Jan-10 22:44 
QuestionDatabase Schema to represent directory structure Pin
Fadi Yoosuf20-Jan-10 6:52
Fadi Yoosuf20-Jan-10 6:52 
AnswerRe: Database Schema to represent directory structure Pin
Bassam Saoud20-Jan-10 8:34
Bassam Saoud20-Jan-10 8:34 
AnswerRe: Database Schema to represent directory structure Pin
Mycroft Holmes20-Jan-10 18:36
professionalMycroft Holmes20-Jan-10 18:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.