473,706 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help with Select @@ Identity


I am using VS 2005 with a formview control trying to insert a record
to my access db. The data is submitted to the main table no problem,
but I need to carry the catID to the bridge table CatalogImage where
imgID also needs to be placed.

Below is my code behind to carry the catID using the Select @@Identity
and insert imgID to the bridge table.

No data is being entered into the bridge table.

Your help is greatly appreciated.

TRU
>Imports System.Data.Ole Db
Partial Class adminMarcell_Ca talogAdd
Inherits System.Web.UI.P age

Protected Sub FormView1_ItemI nserted(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Form ViewInsertedEve ntArgs) Handles FormView1.ItemI nserted
'Declare & Define Connection string
Dim strConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data Source=" & Server.MapPath( "~/App_Data/MarcellCatalog. mdb")
'Declare & Define SQL
Dim strSQL As String = "SELECT @@Identity"

'Create connection object with connection string
Dim Conn As New OleDbConnection (strConn)

'Create command object with SQL and connection oject
Dim Cmd As New OleDbCommand(st rSQL, Conn)

'Declare & Define variable for new id value
Dim newId As Integer
Conn.Open()

'Execute the command and pass the returend result to newId
newId = Cmd.ExecuteScal ar()
Conn.Close()

'Declare and Define new SQL statement using parameter marker (?)
Dim strSQL2 As String = "Insert into CATALOGIMAGE (CatID, ImgID) Values (" & newId & ",?)"
Dim Cmd2 As New OleDbCommand(st rSQL2, Conn)

'Add the parameter to the command, and specify its source
'Reference the DropDownList using FindControl()
Dim ddl As DropDownList = CType(FormView1 .FindControl("I mageDropDown"), DropDownList)

'This is the dropdownlist's selectedValue
Cmd2.Parameters .AddWithValue(" ", ddl.SelectedVal ue)
Conn.Open()

'Execute the SQL to insert the values
Cmd.ExecuteNonQ uery()
Conn.Close()

End Sub
End Class
Apr 15 '07 #1
13 5790
Hi ,
First of all you need to understand that "SELECT @@IDENTITY " is a
connection specific command. It means that if you take two connections to the
database , Insert a single row in a table and run this command using
different connections the result would be different.

So you should do the following to solve your problem :
1. Create a database connection.
2. Create a command object.
3. Open the connection.
4. Insert a row
5. Execute "SELECT @@IDENTITY " without closing or creating a new connection
6.. Performs rest of the steps as you were doing.
Another problem with the following line "newId = Cmd.ExecuteScal ar()" .
newId is integer and ExecuteScalar() returns an object. Use need to convert
that to integer. You can do something like this
Int32.Parse(Cmd .ExecuteScalar( ).ToString()) .

I hope this solves your problem. Feel free to get back in case of any
difficulties.

Regards,
Tushar
"PinkBishop " wrote:
>
I am using VS 2005 with a formview control trying to insert a record
to my access db. The data is submitted to the main table no problem,
but I need to carry the catID to the bridge table CatalogImage where
imgID also needs to be placed.

Below is my code behind to carry the catID using the Select @@Identity
and insert imgID to the bridge table.

No data is being entered into the bridge table.

Your help is greatly appreciated.

TRU
Imports System.Data.Ole Db
Partial Class adminMarcell_Ca talogAdd
Inherits System.Web.UI.P age

Protected Sub FormView1_ItemI nserted(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Form ViewInsertedEve ntArgs) Handles FormView1.ItemI nserted
'Declare & Define Connection string
Dim strConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data Source=" & Server.MapPath( "~/App_Data/MarcellCatalog. mdb")
'Declare & Define SQL
Dim strSQL As String = "SELECT @@Identity"

'Create connection object with connection string
Dim Conn As New OleDbConnection (strConn)

'Create command object with SQL and connection oject
Dim Cmd As New OleDbCommand(st rSQL, Conn)

'Declare & Define variable for new id value
Dim newId As Integer
Conn.Open()

'Execute the command and pass the returend result to newId
newId = Cmd.ExecuteScal ar()
Conn.Close()

'Declare and Define new SQL statement using parameter marker (?)
Dim strSQL2 As String = "Insert into CATALOGIMAGE (CatID, ImgID) Values (" & newId & ",?)"
Dim Cmd2 As New OleDbCommand(st rSQL2, Conn)

'Add the parameter to the command, and specify its source
'Reference the DropDownList using FindControl()
Dim ddl As DropDownList = CType(FormView1 .FindControl("I mageDropDown"), DropDownList)

'This is the dropdownlist's selectedValue
Cmd2.Parameters .AddWithValue(" ", ddl.SelectedVal ue)
Conn.Open()

'Execute the SQL to insert the values
Cmd.ExecuteNonQ uery()
Conn.Close()

End Sub
End Class
Apr 15 '07 #2

Let me start by saying I am very new to VS and .Net. I guess i am
jumping in with both feet to complete this first project. With this
form to be the last part of the project.

Unless I do not understand you, which is a good possiblity, I believe
I have accomplished the first four items of your list. with my form
page. As explained below, I am able to get my data submitted into the
first table with my form. It was my hope through help from another
board that a code behind doing the select @@identity would pass the
catID and imgID to the bridge table. Isn't the code behind steps 5
and 6?

Thanks,

TRU

On Sat, 14 Apr 2007 21:38:04 -0700, Tushar
<Tu****@discuss ions.microsoft. comwrote:
>Hi ,
First of all you need to understand that "SELECT @@IDENTITY " is a
connection specific command. It means that if you take two connections to the
database , Insert a single row in a table and run this command using
different connections the result would be different.

So you should do the following to solve your problem :
1. Create a database connection.
2. Create a command object.
3. Open the connection.
4. Insert a row
5. Execute "SELECT @@IDENTITY " without closing or creating a new connection
6.. Performs rest of the steps as you were doing.
Another problem with the following line "newId = Cmd.ExecuteScal ar()" .
newId is integer and ExecuteScalar() returns an object. Use need to convert
that to integer. You can do something like this
Int32.Parse(Cm d.ExecuteScalar ().ToString()) .

I hope this solves your problem. Feel free to get back in case of any
difficulties .

Regards,
Tushar
"PinkBishop " wrote:
>>
I am using VS 2005 with a formview control trying to insert a record
to my access db. The data is submitted to the main table no problem,
but I need to carry the catID to the bridge table CatalogImage where
imgID also needs to be placed.

Below is my code behind to carry the catID using the Select @@Identity
and insert imgID to the bridge table.

No data is being entered into the bridge table.

Your help is greatly appreciated.

TRU
>Imports System.Data.Ole Db
Partial Class adminMarcell_Ca talogAdd
Inherits System.Web.UI.P age

Protected Sub FormView1_ItemI nserted(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Form ViewInsertedEve ntArgs) Handles FormView1.ItemI nserted
'Declare & Define Connection string
Dim strConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data Source=" & Server.MapPath( "~/App_Data/MarcellCatalog. mdb")
'Declare & Define SQL
Dim strSQL As String = "SELECT @@Identity"

'Create connection object with connection string
Dim Conn As New OleDbConnection (strConn)

'Create command object with SQL and connection oject
Dim Cmd As New OleDbCommand(st rSQL, Conn)

'Declare & Define variable for new id value
Dim newId As Integer
Conn.Open()

'Execute the command and pass the returend result to newId
newId = Cmd.ExecuteScal ar()
Conn.Close()

'Declare and Define new SQL statement using parameter marker (?)
Dim strSQL2 As String = "Insert into CATALOGIMAGE (CatID, ImgID) Values (" & newId & ",?)"
Dim Cmd2 As New OleDbCommand(st rSQL2, Conn)

'Add the parameter to the command, and specify its source
'Reference the DropDownList using FindControl()
Dim ddl As DropDownList = CType(FormView1 .FindControl("I mageDropDown"), DropDownList)

'This is the dropdownlist's selectedValue
Cmd2.Parameters .AddWithValue(" ", ddl.SelectedVal ue)
Conn.Open()

'Execute the SQL to insert the values
Cmd.ExecuteNonQ uery()
Conn.Close()

End Sub
End Class
Apr 15 '07 #3
Hi
It's ok. You will learn soon.
You are right . You performed steps 1-4 and then 5-6. But the problem is
that all these steps should be performed in a single connection.
From the code that you have written what i feel is that you
open a connection
perform steps 1-4
close a connection

open a connection
perform steps 5-6...
close the connection

In this case "select @@IDENTITY" won't work because it is connection
specific. All the steps need to be performed under a single connection
object.
The steps 5-6 are been performed when the item has already been inserted.
When you create a new connection to the database , SELECT @@IDENTITY doesn't
work. It doesn't know which value was inserted last.

Just try and perform all these steps in a single go and I am sure it'll
work. Even then if you face a problem feel free to get back to me. I'll
explain it to you through mail or chat.
--
Regards,
Tushar
MCTS - .NET 2.0 Web App
"PinkBishop " wrote:
>
Let me start by saying I am very new to VS and .Net. I guess i am
jumping in with both feet to complete this first project. With this
form to be the last part of the project.

Unless I do not understand you, which is a good possiblity, I believe
I have accomplished the first four items of your list. with my form
page. As explained below, I am able to get my data submitted into the
first table with my form. It was my hope through help from another
board that a code behind doing the select @@identity would pass the
catID and imgID to the bridge table. Isn't the code behind steps 5
and 6?

Thanks,

TRU

On Sat, 14 Apr 2007 21:38:04 -0700, Tushar
<Tu****@discuss ions.microsoft. comwrote:
Hi ,
First of all you need to understand that "SELECT @@IDENTITY " is a
connection specific command. It means that if you take two connections to the
database , Insert a single row in a table and run this command using
different connections the result would be different.

So you should do the following to solve your problem :
1. Create a database connection.
2. Create a command object.
3. Open the connection.
4. Insert a row
5. Execute "SELECT @@IDENTITY " without closing or creating a new connection
6.. Performs rest of the steps as you were doing.
Another problem with the following line "newId = Cmd.ExecuteScal ar()" .
newId is integer and ExecuteScalar() returns an object. Use need to convert
that to integer. You can do something like this
Int32.Parse(Cmd .ExecuteScalar( ).ToString()) .

I hope this solves your problem. Feel free to get back in case of any
difficulties.

Regards,
Tushar
"PinkBishop " wrote:
>
I am using VS 2005 with a formview control trying to insert a record
to my access db. The data is submitted to the main table no problem,
but I need to carry the catID to the bridge table CatalogImage where
imgID also needs to be placed.

Below is my code behind to carry the catID using the Select @@Identity
and insert imgID to the bridge table.

No data is being entered into the bridge table.

Your help is greatly appreciated.

TRU

Imports System.Data.Ole Db
Partial Class adminMarcell_Ca talogAdd
Inherits System.Web.UI.P age

Protected Sub FormView1_ItemI nserted(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Form ViewInsertedEve ntArgs) Handles FormView1.ItemI nserted
'Declare & Define Connection string
Dim strConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data Source=" & Server.MapPath( "~/App_Data/MarcellCatalog. mdb")
'Declare & Define SQL
Dim strSQL As String = "SELECT @@Identity"

'Create connection object with connection string
Dim Conn As New OleDbConnection (strConn)

'Create command object with SQL and connection oject
Dim Cmd As New OleDbCommand(st rSQL, Conn)

'Declare & Define variable for new id value
Dim newId As Integer
Conn.Open()

'Execute the command and pass the returend result to newId
newId = Cmd.ExecuteScal ar()
Conn.Close()

'Declare and Define new SQL statement using parameter marker (?)
Dim strSQL2 As String = "Insert into CATALOGIMAGE (CatID, ImgID) Values (" & newId & ",?)"
Dim Cmd2 As New OleDbCommand(st rSQL2, Conn)

'Add the parameter to the command, and specify its source
'Reference the DropDownList using FindControl()
Dim ddl As DropDownList = CType(FormView1 .FindControl("I mageDropDown"), DropDownList)

'This is the dropdownlist's selectedValue
Cmd2.Parameters .AddWithValue(" ", ddl.SelectedVal ue)
Conn.Open()

'Execute the SQL to insert the values
Cmd.ExecuteNonQ uery()
Conn.Close()

End Sub
End Class
Apr 15 '07 #4
Tushar,

I understand what you are saying about the need for everthing to
happen under a single connection.

Right now I have steps 1-4 completed in the .aspx file then my
attempt was to complete 5-6 with the .aspx.vb code behind. Now I
realize that can't be done.

How do I complete this in one connection?

or
Is there a way to get the primary key of the last record inserted into
table 1 so to insert into table 2?

Now that I think more, I still need the value from the dropdown as
well.

So, after the insert into table 1 is there a way to call the catID and
imgID from Table 1 and insert into table 2?

There will not be a risk of getting the wrong catID as there will
always be only 1 person entering into the db at a time. I do say
always lightly though.

TRU

On Sat, 14 Apr 2007 22:38:02 -0700, Tushar
<Tu****@discuss ions.microsoft. comwrote:
>Hi
It's ok. You will learn soon.
You are right . You performed steps 1-4 and then 5-6. But the problem is
that all these steps should be performed in a single connection.
From the code that you have written what i feel is that you
open a connection
perform steps 1-4
close a connection

open a connection
perform steps 5-6...
close the connection

In this case "select @@IDENTITY" won't work because it is connection
specific. All the steps need to be performed under a single connection
object.
The steps 5-6 are been performed when the item has already been inserted.
When you create a new connection to the database , SELECT @@IDENTITY doesn't
work. It doesn't know which value was inserted last.

Just try and perform all these steps in a single go and I am sure it'll
work. Even then if you face a problem feel free to get back to me. I'll
explain it to you through mail or chat.
Apr 15 '07 #5
Run the first insert in the same batch with the select that will return you
the id:

"INSERT ...;SELECT SCOPE_IDENTITY( )"

Then use the returned id in the second insert.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"PinkBishop " <pi********@hot mail.comwrote in message
news:t3******** *************** *********@4ax.c om...
>
I am using VS 2005 with a formview control trying to insert a record
to my access db. The data is submitted to the main table no problem,
but I need to carry the catID to the bridge table CatalogImage where
imgID also needs to be placed.

Below is my code behind to carry the catID using the Select @@Identity
and insert imgID to the bridge table.

No data is being entered into the bridge table.

Your help is greatly appreciated.

TRU
>>Imports System.Data.Ole Db
Partial Class adminMarcell_Ca talogAdd
Inherits System.Web.UI.P age

Protected Sub FormView1_ItemI nserted(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Form ViewInsertedEve ntArgs) Handles
FormView1.Item Inserted
'Declare & Define Connection string
Dim strConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
Source=" & Server.MapPath( "~/App_Data/MarcellCatalog. mdb")
'Declare & Define SQL
Dim strSQL As String = "SELECT @@Identity"

'Create connection object with connection string
Dim Conn As New OleDbConnection (strConn)

'Create command object with SQL and connection oject
Dim Cmd As New OleDbCommand(st rSQL, Conn)

'Declare & Define variable for new id value
Dim newId As Integer
Conn.Open()

'Execute the command and pass the returend result to newId
newId = Cmd.ExecuteScal ar()
Conn.Close()

'Declare and Define new SQL statement using parameter marker (?)
Dim strSQL2 As String = "Insert into CATALOGIMAGE (CatID, ImgID)
Values (" & newId & ",?)"
Dim Cmd2 As New OleDbCommand(st rSQL2, Conn)

'Add the parameter to the command, and specify its source
'Reference the DropDownList using FindControl()
Dim ddl As DropDownList =
CType(FormView 1.FindControl(" ImageDropDown") , DropDownList)

'This is the dropdownlist's selectedValue
Cmd2.Parameters .AddWithValue(" ", ddl.SelectedVal ue)
Conn.Open()

'Execute the SQL to insert the values
Cmd.ExecuteNonQ uery()
Conn.Close()

End Sub
End Class

Apr 15 '07 #6
"PinkBishop " <pi********@hot mail.comwrote in message
news:vu******** *************** *********@4ax.c om...
Is there a way to get the primary key of the last record inserted into
table 1 so to insert into table 2?
Don't even think of trying to do this... It will almost certainly fail as
soon as you have more than one user on the system... Use Eliyahu's
suggestion.
Apr 15 '07 #7
Hi Pink,
There is a work around way. But that is a bad practise. As you said only
one user will be using this application you can do this.
Insteat of writing SELECT @@IDENTITY in your code , you can write SELECT TOP
CATID FROM Categories . Since it is an auto increment , you'll always get the
highest value which would be same like SELECT @@IDENTITY . But this would
only work if one user is using the app.
This is a bad practise. I would suggest you to follow SELECT @@IDENTITY and
that too in a single batch.

--
Regards,
Tushar
MCTS - .NET 2.0 Web App
"PinkBishop " wrote:
Tushar,

I understand what you are saying about the need for everthing to
happen under a single connection.

Right now I have steps 1-4 completed in the .aspx file then my
attempt was to complete 5-6 with the .aspx.vb code behind. Now I
realize that can't be done.

How do I complete this in one connection?

or
Is there a way to get the primary key of the last record inserted into
table 1 so to insert into table 2?

Now that I think more, I still need the value from the dropdown as
well.

So, after the insert into table 1 is there a way to call the catID and
imgID from Table 1 and insert into table 2?

There will not be a risk of getting the wrong catID as there will
always be only 1 person entering into the db at a time. I do say
always lightly though.

TRU

On Sat, 14 Apr 2007 22:38:02 -0700, Tushar
<Tu****@discuss ions.microsoft. comwrote:
Hi
It's ok. You will learn soon.
You are right . You performed steps 1-4 and then 5-6. But the problem is
that all these steps should be performed in a single connection.
From the code that you have written what i feel is that you
open a connection
perform steps 1-4
close a connection

open a connection
perform steps 5-6...
close the connection

In this case "select @@IDENTITY" won't work because it is connection
specific. All the steps need to be performed under a single connection
object.
The steps 5-6 are been performed when the item has already been inserted.
When you create a new connection to the database , SELECT @@IDENTITY doesn't
work. It doesn't know which value was inserted last.

Just try and perform all these steps in a single go and I am sure it'll
work. Even then if you face a problem feel free to get back to me. I'll
explain it to you through mail or chat.
Apr 15 '07 #8
Ok... I am scrapping the hole idea of the Formview and going with a
simple form with parameters in the code behind. As the code below
shows the data is submitted off the click of the button to table 1
(Catalog)

Where and how do I implement the Select @@Identity.

I need catID and imgID passed to table 2 CatalogImage
--------------.ASPX PAGE-------------
<%@ Page Language="VB" AutoEventWireup ="false"
CodeFile="Catal ogAdd.aspx.vb" Inherits="admin _CatalogAdd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;<br />
&nbsp;<asp:Acce ssDataSource ID="CatalogData Source"
runat="server" DataFile="~/App_Data/DATABASE.mdb"
DeleteCommand=" DELETE FROM [Catalog] WHERE [catID] = ?"
InsertCommand=" INSERT INTO [Catalog] ([catNum], [catPrice],
[catDescription], [imgID], [venID], [subID]) VALUES (?, ?, ?, ?, ?,
?)"
SelectCommand=" SELECT [catID], [catNum], [catPrice],
[catDescription], [imgID], [venID], [subID] FROM [Catalog]"
UpdateCommand=" UPDATE [Catalog] SET [catNum] = ?,
[catPrice] = ?, [catDescription] = ?, [imgID] = ?, [venID] = ?,
[subID] = ? WHERE [catID] = ?">
<DeleteParamete rs>
<asp:Paramete r Name="catID" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="catNum" Type="Int32" />
<asp:Paramete r Name="catPrice" Type="Int32" />
<asp:Paramete r Name="catDescri ption" Type="String" />
<asp:Paramete r Name="imgID" Type="Int32" />
<asp:Paramete r Name="venID" Type="Int32" />
<asp:Paramete r Name="subID" Type="Int32" />
<asp:Paramete r Name="catID" Type="Int32" />
</UpdateParameter s>
<InsertParamete rs>

<asp:Paramete r Name="catNum" Type="Int32" />
<asp:Paramete r Name="catPrice" Type="Int32" />
<asp:Paramete r Name="catDescri ption" Type="String" />
<asp:Paramete r Name="imgID" Type="Int32" />
<asp:Paramete r Name="venID" Type="Int32" />
<asp:Paramete r Name="subID" Type="Int32" />
</InsertParameter s>
</asp:AccessDataS ource>
<asp:AccessData Source ID="ImageDataSo urce" runat="server"
DataFile="~/App_Data/DATABASE.mdb"
SelectCommand=" SELECT [imgID], [imgName] FROM [Images]
ORDER BY [imgName]"></asp:AccessDataS ource>
</div>
<asp:AccessData Source ID="VendorDataS ource" runat="server"
DataFile="~/App_Data/DATABASE.mdb"
DeleteCommand=" DELETE FROM [Vendors] WHERE [venID] = ?"
InsertCommand=" INSERT INTO [Vendors] ([venID], [venName]) VALUES (?,
?)"
SelectCommand=" SELECT [venID], [venName] FROM [Vendors]
ORDER BY [venName]" UpdateCommand=" UPDATE [Vendors] SET [venName] = ?
WHERE [venID] = ?">
<DeleteParamete rs>
<asp:Paramete r Name="venID" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="venName" Type="String" />
<asp:Paramete r Name="venID" Type="Int32" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="venID" Type="Int32" />
<asp:Paramete r Name="venName" Type="String" />
</InsertParameter s>
</asp:AccessDataS ource>
<asp:AccessData Source ID="CategoryDat aSource" runat="server"
DataFile="~/App_Data/DATABASE.mdb"
DeleteCommand=" DELETE FROM [SubCategory] WHERE [subID] =
?" InsertCommand=" INSERT INTO [SubCategory] ([subID], [SubCategory])
VALUES (?, ?)"
SelectCommand=" SELECT [subID], [SubCategory] FROM
[SubCategory] ORDER BY [SubCategory]"
UpdateCommand=" UPDATE [SubCategory] SET [SubCategory] = ?
WHERE [subID] = ?">
<DeleteParamete rs>
<asp:Paramete r Name="subID" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="SubCatego ry" Type="String" />
<asp:Paramete r Name="subID" Type="Int32" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="subID" Type="Int32" />
<asp:Paramete r Name="SubCatego ry" Type="String" />
</InsertParameter s>
</asp:AccessDataS ource>
<br />
<br />
<asp:Label ID="Label1" runat="server" Style="position : static"
Text="Item"></asp:Label>
<asp:TextBox ID="catNumTxt" runat="server" Style="position :
static"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Style="position : static"
Text="Price"></asp:Label>
<asp:TextBox ID="catPriceTxt " runat="server" Style="position :
static"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Style="position : static"
Text="Descripti on"></asp:Label>
<asp:TextBox ID="CatDescript ionTxt" runat="server"
Style="position : static"></asp:TextBox><br />
<asp:Label ID="Label4" runat="server" Style="position : static"
Text="Image"></asp:Label>
<asp:DropDownLi st ID="ImageDropDo wn" runat="server"
DataSourceID="I mageDataSource"
DataTextField=" imgName" DataValueField= "imgID"
Style="position : static">
</asp:DropDownLis t><br />
<asp:Label ID="Label5" runat="server" Style="position : static"
Text="Vendor"></asp:Label>
<asp:DropDownLi st ID="VendorDropD own" runat="server"
DataSourceID="V endorDataSource "
DataTextField=" venName" DataValueField= "venID"
Style="position : static">
</asp:DropDownLis t><br />
<asp:Label ID="Label6" runat="server" Style="position : static"
Text="Category" ></asp:Label>
<asp:DropDownLi st ID="CategoryDro pDown" runat="server"
DataSourceID="C ategoryDataSour ce"
DataTextField=" SubCategory" DataValueField= "subID"
Style="position : static">
</asp:DropDownLis t><br />
<br />
<asp:Button ID="Button1" runat="server" Style="position :
static" Text="Submit" />
</form>
</body>
</html>


--------------.VB CODE BEHIND-------------
Partial Class admin_CatalogAd d
Inherits System.Web.UI.P age

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click
CatalogDataSour ce.InsertParame ters("catNum"). DefaultValue =
catNumTxt.Text
CatalogDataSour ce.InsertParame ters("catPrice" ).DefaultValue =
catPriceTxt.Tex t
CatalogDataSour ce.InsertParame ters("catDescri ption").Default Value =
CatDescriptionT xt.Text
CatalogDataSour ce.InsertParame ters("imgID").D efaultValue =
ImageDropDown.S electedValue
CatalogDataSour ce.InsertParame ters("venID").D efaultValue =
VendorDropDown. SelectedValue
CatalogDataSour ce.InsertParame ters("subID").D efaultValue =
CategoryDropDow n.SelectedValue

CatalogDataSour ce.Insert()
End Sub
End Class

Apr 15 '07 #9
"PinkBishop " <pi********@hot mail.comwrote in message
news:t6******** *************** *********@4ax.c om...
Where and how do I implement the Select @@Identity.
This has already been explained to you at least twice...

You simply include your insert statement and your SELECT @@IDENTITY
statement in the same SQL batch:

INSERT.....
SELECT @@IDENTITY

Then, when you run your SQL, it will first do the insert and then return you
the ID that you require...
Apr 15 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4367
by: Jason Callas | last post by:
I have a stored procedure that runs as a step in a scheduled job. For some reason the job does not seem to finish when ran from the job but does fine when run from a window in SQL Query. I know the job is not working because the number of rows that are inserted into the table (see code) is considerably less than the manual runnning of it. I have included the code for the stored procedure, the output from the job, and the output from...
9
4758
by: Not Me | last post by:
Hi, I'm trying to grab records with a priority over those marked as yes (-1) in a certain field. Trying "select id, min(bit) from tab group by id" does not work, as the min operator doesn't work on bits. Is there an alternative to my query?
3
337
by: AMD Desktop | last post by:
Here is the table: CREATE TABLE ( IDENTITY (1, 1) NOT NULL , NOT NULL , NOT NULL , NOT NULL CONSTRAINT DEFAULT (0), NOT NULL , NOT NULL ) ON
1
15426
by: php newbie | last post by:
I have the following query that has been working so far. I modified it slightly to work from another source table (new_products). Now, SQL Server complains that the identity is inherited already: "Cannot add identity column, using the SELECT INTO statement, to table 'dbo.my_products', which already has column 'id' that inherits the identity property." Any suggestions for a work aorund?
1
1660
by: Tony | last post by:
Thanks for writing back and don't laugh at what I am about to post I am new to this type of stuff....this is what I have tried and it isn't working(please note in the try section I was just trying to see if it was grabbing my variable or not any suggestions or hints would be greatly appreciated: ******** Private Sub AddArticle()
9
2762
by: Ed_No_Spam_Please_Weber | last post by:
Hello All & Thanks in advance for your help! Background: 1) tblT_Documents is the primary parent transaction table that has 10 fields and about 250,000 rows 2) There are 9 child tables with each having 3 fields each, their own PK; the FK back to the parent table; and the unique data for that table. There is a one to many relation between the parent and each of the 9 child rows. Each child table has between 100,000 and 300,000
0
3156
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these datacolumns do not trigger their expression when other columns from which the expressions are derived are updated. Below is a basic example of what I am doing. User enters values into an asp.net form and clicks a button. Retrieve dataset from...
3
3017
by: anoop | last post by:
Hello, I have written code in ASP.net 2.0 to insert the values in a SQL Server Database. the code is as follows Dim addemp As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("INSERT INTO Department (department_name,lastname,firstname,title,hiredate,reportsto,photo) values(@departmentname,@lastname,@firstname,@title,@hiredate,@reportsto,0x0);" & "SELECT @identity=SCOPE_IDENTITY();" & "SELECT...
4
1938
by: kyle.fitzgerald | last post by:
I'm just know basic SQL but not enough to write any complex queries. The problem I'm facing right now keeps me thinking to use a Cursor but I've seen a lot of posts on here saying Cursors are bad so I'm hoping there is a complex query that can give me the data I need. I have about 6 pages in website where I need to display a datagrid of information. There should be 5 columns, Filename, and then 4 Category Titles (These category titles...
0
8781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8696
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9285
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9050
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7906
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4448
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4709
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.