Join 132,396 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,236 people online right now. Registration is fast and FREE... Join Now!
Is this stored procedure to copy data from one table to the other i have the code here its giving me realtion ship problems
sql
ALTER PROCEDURE dbo.CopyRecords
(
@UserName nvarchar(50), @OrderDate datetime, @OrderTime datetime, @AuthorizationCode text )
AS insert into OrderedItem (StoreID,MenuID,ProductID,ItemName,Quantity,Price,Username,OrderDate,OrderTime,A uthorizationCode) Select StoreID,MenuID,ProductID,ItemName,Quantity,Price,Username,@OrderDate,@OrderTime, @AuthorizationCode from Item where Item.Username = @Username RETURN
above i s the code for the stored procedure
below is the code on in the subprocedure
vb
Try
mclass.connect() Dim sql As String = "Select * from Item where Username = '" & Session("Username") & "'" mclass.cmd.CommandText = sql mclass.cmd.CommandType = CommandType.Text mclass.dtr = mclass.cmd.ExecuteReader
Dim sID, prodID, mID, Quant As Integer Dim money As Decimal Dim itemNam, Usernam As String
If mclass.dtr.Read Then sID = mclass.dtr("StoreID") mID = mclass.dtr("MenuID") prodID = mclass.dtr("ProductID") itemNam = mclass.dtr("ItemName") Quant = mclass.dtr("Quantity") money = mclass.dtr("Price") Usernam = mclass.dtr("Username") mclass.dtr.Close() End If '@ItemName nchar(20), ' @Quantity int, ' @Price money, ' @UserName nvarchar(50), ' @OrderDate datetime, ' @OrderTime datetime, ' @AuthorizationCode text
' Dim query As String = "Insert into OrderedItem (StoreID,MenuID,ProductID,ItemName,Quantity,Price,Username,OrderDate,OrderTime,A uthorizationCode) Select StoreID,MenuID,ProductID,ItemName,Quantity," & total & ",'" & Session("Username") & "', '" & odate & "','" & Otime & "','" & autoCode & "' from Item where Item.Username = '" & Session("Username") & "'" mclass.cmd.Connection = mclass.con mclass.cmd.CommandText = "CopyRecords" mclass.cmd.CommandType = CommandType.StoredProcedure
Well your stored procedure I dont see any issues with, well without seeing the code that created each tables. There may or maynot be some relationship issues that need to be worked through. I reformatted your stored procedure for making it easier to read:
sql
ALTER PROCEDURE dbo.CopyRecords @UserName VARCHAR(50), @OrderDate DATETIME, @OrderTime DATETIME, @AuthorizationCode VARCHAR(255) AS INSERT INTO OrderedItem (StoreID,MenuID,ProductID,ItemName,Quantity,Price,Username,OrderDate,OrderTime,A uthorizationCode) SELECT StoreID, MenuID, ProductID, ItemName, Quantity, Price, Username, @OrderDate, @OrderTime, @AuthorizationCode FROM Item WHERE Item.Username = @Username
As far as part number two of your post. You had your SqlParameters all wrong. You were trying to combine AddWithValue() with Add(String, SqlDbType). and that just wont work.
I made some changes to your code using AddWithValue() the way it's meant to be used to see if this will clear up some of your trouble. See if this solves anything for you
vb
Try
mclass.connect() Dim sql As String = "Select * from Item where Username = '" & Session("Username") & "'" mclass.cmd.CommandText = sql mclass.cmd.CommandType = CommandType.Text mclass.dtr = mclass.cmd.ExecuteReader
Dim sID, prodID, mID, Quant As Integer Dim money As Decimal Dim itemNam, Usernam As String
If mclass.dtr.Read Then sID = mclass.dtr("StoreID") mID = mclass.dtr("MenuID") prodID = mclass.dtr("ProductID") itemNam = mclass.dtr("ItemName") Quant = mclass.dtr("Quantity") money = mclass.dtr("Price") Usernam = mclass.dtr("Username") mclass.dtr.Close() End If