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
13 5766
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
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
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
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.
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
"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.
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.
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>
<br />
<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
"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... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
...
|
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?
|
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
|
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...
|
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()
| |
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...
|
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...
|
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)...
|
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...
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
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...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |