va80
asked on
ID from saved information in database problem
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.Dat aObjectMet hodAttribu te(System. ComponentM odel.DataO bjectMetho dType.Sele ct, false)]
public DAL.reiterDataTable getReiterByReiterID(int reiterid)
{
return Adapter.GetReiterByID(reit erid);
}
[System.ComponentModel.Dat aObjectMet hodAttribu te(System. ComponentM odel.DataO bjectMetho dType.Inse rt, 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.In sertReiter (Vorname, Nachname, Verein, Land, Pferd_name, Pferd_ID, Pferd_herkunftsland));
return localreiterID;
}
Presentation layer
ObjectDataSource1.InsertPa rameters[" vorname"]. DefaultVal ue = Vorname.Text;
ObjectDataSource1.InsertPa rameters[" nachname"] .DefaultVa lue = Nachname.Text;
ObjectDataSource1.InsertPa rameters[" verein"].D efaultValu e = Verein.Text;
ObjectDataSource1.InsertPa rameters[" land"].Def aultValue = Land.Text;
ObjectDataSource1.InsertPa rameters[" Pferd_name "].Default Value = Name.Text;
ObjectDataSource1.InsertPa rameters[" Pferd_ID"] .DefaultVa lue = FeifID.Text;
ObjectDataSource1.InsertPa rameters[" Pferd_herk unftsland" ].DefaultV alue = Pferd_Land.Text;
int reiterint = ObjectDataSource1.Insert() ;
Nachname.Text = reiterint.ToString();:
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.Dat
public DAL.reiterDataTable getReiterByReiterID(int reiterid)
{
return Adapter.GetReiterByID(reit
}
[System.ComponentModel.Dat
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.In
return localreiterID;
}
Presentation layer
ObjectDataSource1.InsertPa
ObjectDataSource1.InsertPa
ObjectDataSource1.InsertPa
ObjectDataSource1.InsertPa
ObjectDataSource1.InsertPa
ObjectDataSource1.InsertPa
ObjectDataSource1.InsertPa
int reiterint = ObjectDataSource1.Insert()
Nachname.Text = reiterint.ToString();:
ASKER
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????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SET @RV=SCOPE_IDENTITY()
RETURN @RV <--this is what sends it back