?
Solved

ID from saved information in database problem

Posted on 2007-04-03
3
Medium Priority
?
183 Views
Last Modified: 2012-03-15
I am saving in Database and getting the ID back of the row saved in the database.  The Information is saved in the database but the ID doesnt come.  The interger which is supposed to have the integer is always -1

any suggestions
SQL in Datalist (DAL):
INSERT INTO [reiter] ([Vorname], [Nachname], [Verein], [Land], [Pferd_name], [Pferd_ID], [Pferd_herkunftsland]) VALUES (@Vorname, @Nachname, @Verein, @Land, @Pferd_name, @Pferd_ID, @Pferd_herkunftsland);

SELECT SCOPE_IDENTITY()

functions in BBL
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
    public DAL.reiterDataTable getReiterByReiterID(int reiterid)
    {
        return Adapter.GetReiterByID(reiterid);
    }
   
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
    public int InsertReiter(string Vorname, string Nachname, string Verein, string Land, string Pferd_name, string Pferd_ID, string Pferd_herkunftsland)
    {

        int localreiterID = Convert.ToInt32(Adapter.InsertReiter(Vorname, Nachname, Verein, Land, Pferd_name, Pferd_ID, Pferd_herkunftsland));
        return localreiterID;        
    }
Presentation layer
ObjectDataSource1.InsertParameters["vorname"].DefaultValue = Vorname.Text;
        ObjectDataSource1.InsertParameters["nachname"].DefaultValue = Nachname.Text;
        ObjectDataSource1.InsertParameters["verein"].DefaultValue = Verein.Text;
        ObjectDataSource1.InsertParameters["land"].DefaultValue = Land.Text;
        ObjectDataSource1.InsertParameters["Pferd_name"].DefaultValue = Name.Text;
        ObjectDataSource1.InsertParameters["Pferd_ID"].DefaultValue = FeifID.Text;
        ObjectDataSource1.InsertParameters["Pferd_herkunftsland"].DefaultValue = Pferd_Land.Text;
        int reiterint =  ObjectDataSource1.Insert();
        Nachname.Text = reiterint.ToString();:
0
Comment
Question by:va80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 18844736
DECLARE @RV INTEGER
SET @RV=SCOPE_IDENTITY()
RETURN @RV             <--this is what sends it back

0
 

Author Comment

by:va80
ID: 18847056
im using visual studio (im new with this) do i put this instead of "select scop...()" in the sql query.  secondly: do you really think the sql queryis  reason for the false ID returned (is always -1).  I´ve used it in other situations with success????
0
 
LVL 42

Accepted Solution

by:
dqmq earned 600 total points
ID: 18950929
Yes, it goes in the TSQL stored procedure, instead of "select scope..."
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question