The thread was interrupted - asp.net

I am using this code to update database with new values. But it return message The thread was interrupted. What does it mean? What is wrong with my code?
Dim connStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("DeskriptivaConnectionString").ConnectionString.ToString()
Dim txtName As Object = DirectCast(FormView1.FindControl("txtName"), TextBox)
Dim txtLastName As Object = DirectCast(FormView1.FindControl("txtLastName"), TextBox)
Dim txtInfo As Object = DirectCast(FormView1.FindControl("txtInfo"), TextBox)
Dim txtCity As Object = DirectCast(FormView1.FindControl("txtCity"), TextBox)
Dim txtPrize As TextBox = DirectCast(FormView1.FindControl("txtPrize"), TextBox)
Dim txtPhone As TextBox = DirectCast(FormView1.FindControl("txtPhone"), TextBox)
Dim txtMail As TextBox = DirectCast(FormView1.FindControl("txtMail"), TextBox)
Try
Using conn As New SqlConnection(connStr)
Dim cmd As SqlCommand = conn.CreateCommand()
cmd.CommandText = "UPDATE Profiles SET #Name = Name, #LastName = LastName, #Info = Info, #City = City, #Prize = Prize, #Phone = Phone, #Mail = Mail WHERE (UserName = #UserName)"
cmd.Parameters.Add("#Name", System.Data.SqlDbType.NVarChar).Value = txtName.Text
cmd.Parameters.Add("#LastName", System.Data.SqlDbType.NVarChar).Value = txtLastName.Text
cmd.Parameters.Add("#Info", System.Data.SqlDbType.NText).Value = MakeLink(HtmlRemoval.StripTagsCharArray(txtInfo.Text))
cmd.Parameters.Add("#City", System.Data.SqlDbType.NVarChar).Value = txtCity.Text
cmd.Parameters.Add("#Prize", System.Data.SqlDbType.NVarChar).Value = txtPrize.Text
cmd.Parameters.Add("#Phone", System.Data.SqlDbType.NVarChar).Value = txtPhone.Text
cmd.Parameters.Add("#Mail", System.Data.SqlDbType.NVarChar).Value = txtMail.Text
cmd.Parameters.Add("#UserName", System.Data.SqlDbType.NVarChar).Value = Context.User.Identity.Name
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Response.Redirect(ResolveClientUrl("~/Profil/"))
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try

Use Response.Redirect(ResolveClientUrl("~/Profil/"), false) with Context.ApplicationInstance.CompleteRequest(); instead of Response.Redirect(ResolveClientUrl("~/Profil/"))
check Correct use of System.Web.HttpResponse.Redirect blog post for more information
and also your sql parameters # symbol is in wrong place. change as below
UPDATE Profiles SET
Name = #Name, LastName
= #LastName, Info =
#Info, City = #City,
Prize = #Prize, Phone
= #Phone, Mail = #Mail
WHERE (UserName =
#UserName)

Related

If statement using SqlDataReader value not working

I am working on a cart/basket page of an e-commerce site. Specifically: "-" link button to decrease quantity of selected product by 1 in the cart, and later the "+" link button to increase quantity of selected product by 1 in the cart.
For the "-" button I am doing:
Check the CategoryID of the product selected.
If the CategoryID = 3 or 4, then:
Check if the quantity of the selected product is more > 1.
Quantity = Quantity - 1.
Reduce the amount of HoursWork (used for booking slot length) for the selected product.
Product Stock + 1.
Reduce the weight (used for delivery price).
Else: label displays "Quantity cannot be changed for Detailing & Valeting services.
I am using a SqlDataReader to get the CategoryID, and then storing it as Integer in variable CategoryID.
I tested by displaying the variable contents in a label, and it collects the correct CategoryID - however the "If CategoryID = "3" or "4" Then... is not working, as all categoryIDs are running the IF section or the statement and not the ELSE section.
Protected Sub lDecrease_Click(ByVal sender As Object, ByVal e As EventArgs)
'get clicked button
Dim lnk As LinkButton = CType(sender, LinkButton)
'Get clicked button row
' Dim row As GridViewRow = CType(lnk.Parent.Parent, GridViewRow)
Dim row As GridViewRow = CType(lnk.NamingContainer, GridViewRow)
'Get row selected
Dim idx As Integer = row.RowIndex
'get CartID
Dim lblCartID As Label = CType(row.Cells(0).FindControl("lblCartID"), Label)
Dim SCCartID As String = lblCartID.Text.ToString
'get ProductID
Dim lblProductID As Label = CType(row.Cells(0).FindControl("lblProductID"), Label)
Dim SCProductID As String = lblProductID.Text.ToString
'get ProductName
Dim lblProduct As Label = CType(row.Cells(0).FindControl("lblProduct"), Label)
Dim SCProduct As String = lblProduct.Text.ToString
'get Size
Dim lblSize As Label = CType(row.Cells(0).FindControl("lblSize"), Label)
Dim SCSize As String = lblSize.Text.ToString
'get Price
Dim lblPrice As Label = CType(row.Cells(0).FindControl("lblPrice"), Label)
Dim SCPrice As String = lblPrice.Text.ToString
'get Quantity
Dim lblQuantity As Label = CType(row.Cells(0).FindControl("lblQuantity"), Label)
Dim SCQuantity As String = lblQuantity.Text.ToString
'get Subtotal
Dim lblSubtotal As Label = CType(row.Cells(0).FindControl("lblSubtotal"), Label)
Dim SCSubtotal As String = lblSubtotal.Text.ToString
'get HoursWork
Dim lblHoursWork As Label = CType(row.Cells(0).FindControl("lblHoursWork"), Label)
Dim SCHoursWork As String = lblHoursWork.Text.ToString
'get Weight
Dim lblWeight As Label = CType(row.Cells(0).FindControl("lblWeight"), Label)
Dim SCWeight As String = lblWeight.Text.ToString
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
' start of category check
Dim cmd4 As SqlCommand = New SqlCommand
cmd4.CommandText = "SELECT products.CategoryID FROM products INNER JOIN Cart on products.ProductID = cart.ProductID WHERE cart.productID=#ProductID"
Dim ProductID2 As SqlParameter = New SqlParameter("#ProductID", SqlDbType.Int, 4)
ProductID2.Value = SCProductID
cmd4.Parameters.Add(ProductID2)
cmd4.Connection = conn
conn.Open()
cmd4.ExecuteNonQuery()
Dim reader As SqlDataReader = cmd4.ExecuteReader
Dim CategoryID As Integer
While reader.Read()
CategoryID = CType(reader.Item("CategoryID"), Integer)
End While
'Testing CategoryID value = success
lblNoStock.Visible = True
lblNoStock.Text = CategoryID
conn.Close()
'Nest IF statement based on Category ID 1,2, cannot be reduced in Quantity
If CategoryID = "3" Or "4" Then
' Run quantity check – And update if possible
Dim exists As Boolean = False
'cart quantity
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "Select Quantity from Cart where CartID = #CartID"
cmd.Connection = conn
' conn.Close()
conn.Open()
'rename cart id 5
Dim CartID5 As SqlParameter = New SqlParameter("#CartID", SqlDbType.Int, 4)
CartID5.Value = SCCartID
cmd.Parameters.Add(CartID5)
'check if more than 1 in cart
exists = (CType(cmd.ExecuteScalar, Integer) > 1)
If exists Then
'show label to say no more in stock
lblNoStock.Visible = True
' lblNoStock.Text = "Available!"
conn.Close()
' update quantity & subtotal
Dim cmd1 As SqlCommand = New SqlCommand
cmd1.CommandText = "UPDATE Cart SET Quantity = Quantity - 1, Subtotal = #Subtotal - #Price WHERE CartID = #CartID"
'update hourswork
Dim cmd2 As SqlCommand = New SqlCommand
cmd2.CommandText = "UPDATE Cart SET HoursWork = (HoursWork - (Select Products.HoursWork FROM Products WHERE Products.ProductID = Cart.ProductID)) WHERE CartID = #CartID"
'UPDATE PRODUCTS STOCK + 1
'"UPDATE Products Set Stock = Stock + 1 WHERE ProductID = #ProductID"
Dim cmd3 As SqlCommand = New SqlCommand
'UPDATE weight
cmd3.CommandText = "UPDATE Cart SET Weight = (Weight - (Select Products.Weight FROM Products WHERE Products.ProductID = Cart.ProductID)) WHERE CartID = #CartID"
cmd1.Connection = conn
cmd2.Connection = conn
cmd3.Connection = conn
conn.Open()
Dim PProductID As SqlParameter = New SqlParameter("#ProductID", SqlDbType.Int, 4)
PProductID.Value = SCProductID
cmd1.Parameters.Add(PProductID)
Dim Subtotal As SqlParameter = New SqlParameter("#Subtotal", SqlDbType.Decimal, 5)
Subtotal.Value = SCSubtotal
cmd1.Parameters.Add(Subtotal)
Dim Price As SqlParameter = New SqlParameter("#Price", SqlDbType.Decimal, 5)
Price.Value = SCPrice
cmd1.Parameters.Add(Price)
Dim CartID As SqlParameter = New SqlParameter("#CartID", SqlDbType.Int, 4)
CartID.Value = SCCartID
cmd1.Parameters.Add(CartID)
Dim CartID2 As SqlParameter = New SqlParameter("#CartID", SqlDbType.Int, 4)
CartID2.Value = SCCartID
cmd2.Parameters.Add(CartID2)
Dim CartID3 As SqlParameter = New SqlParameter("#CartID", SqlDbType.Int, 4)
CartID3.Value = SCCartID
cmd3.Parameters.Add(CartID3)
Try
cmd1.ExecuteNonQuery()
cmd2.ExecuteNonQuery()
cmd3.ExecuteNonQuery()
cmd.ExecuteReader()
'show label to quantity updated
lblNoStock.Visible = True
' lblNoStock.Text = "Updated!"
Finally
conn.Close()
'Response.Redirect("Cart2.aspx")
End Try
Else
'show label to say no more in stock
lblNoStock.Visible = True
lblNoStock.Text = "Cannot reduce quantity: Remove from Cart!"
End If
' else
' lblNoStock.Visible = True
' lblNoStock.Text = "Cannot reduce quantity of Detailing/ Valeting services: Remove from Cart!"
Else
'Outer ELSE
'show label to say cannot change quantity
lblNoStock.Visible = True
lblNoStock.Text = "Quantity cannot be changed for Detailing and Valeting services!"
End If
End Sub
I am also having the same issue with the "+" link button to increase quantity of selected product by 1 in the cart. Reduced code:
Protected Sub lIncrease_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Dim exists As Boolean = False
'Check available in Products table STOCK
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "Select Stock from Products where ProductID = #ProductID"
cmd.Connection = conn
conn.Open()
Dim ProductID As SqlParameter = New SqlParameter("#ProductID", SqlDbType.Int, 4)
ProductID.Value = SCProductID
cmd.Parameters.Add(ProductID)
'check if more than 0 in stock
exists = (CType(cmd.ExecuteScalar, Integer) > 0)
If exists Then
conn.Close()
Dim cmd4 As SqlCommand = New SqlCommand
cmd4.CommandText = "SELECT products.CategoryID FROM products INNER JOIN Cart on products.ProductID = cart.ProductID WHERE cart.productID=#ProductID"
Dim ProductID2 As SqlParameter = New SqlParameter("#ProductID", SqlDbType.Int, 4)
ProductID2.Value = SCProductID
cmd4.Parameters.Add(ProductID2)
cmd4.Connection = conn
conn.Open()
cmd4.ExecuteNonQuery()
Dim reader As SqlDataReader = cmd4.ExecuteReader
Dim CategoryID As Integer
While reader.Read()
CategoryID = CType(reader.Item("CategoryID"), Integer)
End While
'Testing CategoryID value = success
' lblNoStock.Visible = True
'lblNoStock.Text = CategoryID
conn.Close()
'NESTED IF STATEMENT
If CategoryID = "3" Or "4" Then
' UPDATE cart QUANTITY & SUBTOTAL based on CartID
cmd1.CommandText = "UPDATE Cart SET Quantity = Quantity + 1, Subtotal = #Subtotal + #Price WHERE CartID = #CartID"
Dim cmd2 As SqlCommand = New SqlCommand
'UPDATE cart HOURSWORK
cmd2.CommandText = "/"
Dim cmd3 As SqlCommand = New SqlCommand
'UPDATE cart HOURSWORK
cmd3.CommandText = "/"
cmd1.Connection = conn
cmd2.Connection = conn
cmd3.Connection = conn
conn.Open()
//Declared Parameters
Try
cmd1.ExecuteNonQuery()
cmd2.ExecuteNonQuery()
cmd3.ExecuteNonQuery()
cmd.ExecuteReader()
Finally
conn.Close()
Response.Redirect("Cart2.aspx")
End Try
Else
'Nested ELSE
'show label to say cannot change quantity
lblNoStock.Visible = True
lblNoStock.Text = "Quantity cannot be changed for Detailing and Valeting services!"
End If
Else
'show label to say no more in stock
lblNoStock.Visible = True
lblNoStock.Text = "Sorry out of stock!"
End If
End Sub
Two tables:
CART (CartID, UserID, DateCreated, ProductID, ProductName, Size, Price, Quantity, Subtotal, HoursWork)
PRODUCTS (ProductID, Name, SDescription, Price, Size, Images, Thumbnail, Weight, LDescription, Stock, CategoryID, HoursWork)
All working correctly now.
Changed from:
Dim reader As SqlDataReader = cmd4.ExecuteReader
Dim CategoryID As Integer
While reader.Read()
CategoryID = CType(reader.Item("CategoryID"), Integer)
End While
conn.Close()
If CategoryID = "3" Or "4" Then
To:
Dim reader As SqlDataReader = cmd4.ExecuteReader
While reader.Read()
lblTest3.Text = CType(reader.Item("CategoryID"), Integer)
End While
conn.Close()
If lblTest3.Text.Contains("3") Or lblTest3.Text.Contains("4") Then

the for loop check the user and every time the both if statement is checked i want only one statement should be checked

Dim LoginUser As MembershipUser = Membership.GetUser(HttpContext.Current.User.Identity.Name)
Dim sFormat As String = "00.00"
'Dim LoginUser = "P002"
Dim sqlapt As SqlDataAdapter = New SqlDataAdapter("select * from wpchannel", connection)
Dim sqlds As DataSet = New DataSet()
Dim sqldt As DataTable = New DataTable()
sqlapt.Fill(sqlds, "wpaccess")
sqldt = sqlds.Tables(0)
'Dim sum As Double
Dim row As DataRow
For Each row In sqldt.Rows
Dim strDetail As String
strDetail = row("username")
lbluserchk.Text = strDetail
If lbluserchk.Text = LoginUser.ToString Then
Dim sqlapt1 As SqlDataAdapter = New SqlDataAdapter("select * from wpchannel where username='" + LoginUser.ToString + "'", connection)
Dim sqlds1 As DataSet = New DataSet()
Dim sqldt1 As DataTable = New DataTable()
sqlapt1.Fill(sqlds1, "wpchannel")
sqldt1 = sqlds1.Tables(0)
Dim username As String = sqldt1.Rows(0).Item(1).ToString
Dim productid As String = sqldt1.Rows(0).Item(2).ToString
lblcheck1.Text = username.ToString
lblcheck2.Text = productid
'New check
Dim da As SqlDataAdapter
Dim ds As DataSet = New DataSet()
Dim dt As DataTable = New DataTable()
Dim sqlquery2 = "select convert(varchar(10), convert(datetime, dn.curdatetime),20) as DnDate ,DN.telcoid As TelecoId,round(convert(decimal(18,2),DN.USD),2) as USD,DN.DNStatus As DnStatus,count(*) as Total,sum(round(convert(decimal(18,2),DN.USD),2)) as subtotal from DN left join MO on DN.moid = mo.linkid where mo.channeltype in (select channelid from wpchannel where username='" + LoginUser.ToString + "') Group by convert(varchar(10), convert(datetime, dn.curdatetime),20),DN.telcoid,DN.USD,DN.DNStatus order by DnDate,dn.telcoid,dnstatus,USD"
da = New SqlDataAdapter(sqlquery2, connection)
da.Fill(ds, "MO")
dt = ds.Tables(0)
ViewState("dtpayment") = dt
Session("dtpayment") = dt
GridView1.DataSource = dt
GridView1.DataBind()
GridView1.FooterRow.Cells(2).Font.Bold = True
GridView1.FooterRow.Cells(2).ForeColor = Color.Black
GridView1.FooterRow.Cells(2).Text = " Grand Total:"
GridView1.FooterRow.Cells(2).HorizontalAlign = HorizontalAlign.Right
Dim sum As Double = Convert.ToDouble(dt.Compute("SUM(" + (dt.Columns(5).ColumnName) + ")", String.Empty))
Dim footernum As Double = sum.ToString
GridView1.FooterRow.Cells(3).Text = footernum.ToString()
Dim sumnum As Double = sum.ToString
lblsum.Text = sumnum.ToString()
ViewState("dt") = dt
ViewState("sort") = "Asc"
VerifyRenderingInServerForm(GridView1)
Exit For
Else
Dim cmd As SqlCommand
Dim da1 As SqlDataAdapter
Dim ds1 As DataSet = New DataSet()
Dim dt1 As DataTable = New DataTable()
'Dim sqlquery1 = "select convert(varchar(10), convert(datetime, dn.curdatetime),20) as DnDate ,DN.telcoid As TelecoId,round(convert(decimal(18,2),DN.USD),2) as USD,DN.DNStatus As DnStatus,count(*) as Total from DN left join MO on DN.moid = mo.linkid Group by convert(varchar(10), convert(datetime, dn.curdatetime),20),DN.telcoid,DN.USD,DN.DNStatus order by DnDate DESC,dn.telcoid,dnstatus,USD"
cmd = New SqlCommand
cmd.Connection = connection
cmd.CommandText = "logReport"
cmd.CommandType = CommandType.StoredProcedure
da1 = New SqlDataAdapter(cmd)
da1.Fill(ds1, "MO")
dt1 = ds1.Tables(0)
ViewState("dtpayment") = dt1
Session("dtpayment") = dt1
GridView1.DataSource = dt1
GridView1.DataBind()
GridView1.FooterRow.Cells(2).Font.Bold = True
GridView1.FooterRow.Cells(2).ForeColor = Color.Black
GridView1.FooterRow.Cells(2).Text = " Grand Total:"
GridView1.FooterRow.Cells(2).HorizontalAlign = HorizontalAlign.Right
Dim sum As Double = Convert.ToDouble(dt1.Compute("SUM(" + dt1.Columns(2).ColumnName + ")", String.Empty)) * Convert.ToDouble(dt1.Compute("SUM(" + dt1.Columns(4).ColumnName + ")", String.Empty))
Dim footernum As Double = sum
GridView1.FooterRow.Cells(3).Text = footernum.ToString()
Dim sumnum As Double = sum.ToString
lblsum.Text = sumnum.ToString()
ViewState("dt") = dt1
ViewState("sort") = "Asc"
VerifyRenderingInServerForm(GridView1)
Continue For
End If
'Exit Sub
Next row
Catch ex As Exception
Label1.Text = ex.ToString
'jscript = ("<script language=""JavaScript"">alert(""Error! Cannot conect to the database."");</script>")
'RegisterClientScriptBlock(x, jscript)
End Try

How to rebind grid view after update?

May I know how to rebind data to grid view table after update? Below is what I have tried so far:
Dim conn As New MySqlConnection
conn.ConnectionString = "server = localhost; user id = root; password = root; database = db_fyp"
Dim com As New MySqlCommand
Dim dt As New DataTable
Dim query As String
query = "update tblorder set OrderStatus = #OrderStatus where UserId = #UserId "
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("#OrderStatus", tOrderStatus)
com.Parameters.AddWithValue("#UserId", Session("Username"))
conn.Open()
com.ExecuteNonQuery()
BindData()
conn.Close()
Here is my BindData function for insert data into grid view table. This part is working perfectly.
Private Sub BindData()
Dim conn As New MySqlConnection
conn.ConnectionString = "server = localhost; user id = root; password = root; database = db_fyp"
Dim com As New MySqlCommand
Dim dr As MySqlDataReader
Dim query As String
Dim dt As New DataTable
conn.Open()
query = "select FoodName, Qty, IngredientName, Quantity, OrderStatus from tblorder, tblorderdetail, tblfood, tblcustomizefooddetail, tblcustomizeingredient, tblordercustomize where UserId = #UserId and OrderStatus = #OrderStatus and tblorder.OrderId = tblorderdetail.OrderId and tblorderdetail.FoodId = tblfood.FoodId and tblorderdetail.OrderDetailId = tblordercustomize.OrderDetailId and tblfood.FoodId = tblcustomizefooddetail.FoodId and tblcustomizeingredient.IngredientId = tblcustomizefooddetail.IngredientId and tblordercustomize.IngredientId = tblcustomizeingredient.IngredientId"
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("#UserId", Session("Username"))
com.Parameters.AddWithValue("#OrderStatus", "Pending")
dr = com.ExecuteReader
dt.Load(dr)
Session("OderTable") = dt
GridView1.DataSource = dt
GridView1.DataBind()
conn.Close()
End Sub
you already have a function to populate the grid, simply call it from within the updating code:
Dim conn As New MySqlConnection
conn.ConnectionString = "server = localhost; user id = root; password = root; database = db_fyp"
Dim com As New MySqlCommand
Dim dt As New DataTable
Dim query As String
query = "update tblorder set OrderStatus = #OrderStatus where UserId = #UserId "
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("#OrderStatus", tOrderStatus)
com.Parameters.AddWithValue("#UserId", Session("Username"))
conn.Open()
com.ExecuteNonQuery()
conn.Close()
'you dont need all that
'dt.Load(????)
'GridView1.DataSource = dt
'GridView1.DataBind()
'just call this
BindData()

Search record in grid view

The read record is solved. I still have another problem the error message still remain there after user key in correct order id.
query = "select FoodName, Qty, IngredientName, Quantity, OrderStatus
from tblorder, tblorderdetail, tblfood, tblcustomizefooddetail, tblcustomizeingredient, tblordercustomize
where tblOrder.OrderId = #OrderId and OrderStatus = #OrderStatus and tblorder.OrderId = tblorderdetail.OrderId and tblorderdetail.FoodId = tblfood.FoodId and tblorderdetail.OrderDetailId = tblordercustomize.OrderDetailId and tblfood.FoodId = tblcustomizefooddetail.FoodId and tblcustomizeingredient.IngredientId = tblcustomizefooddetail.IngredientId and tblordercustomize.IngredientId = tblcustomizeingredient.IngredientId"
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("#OrderId", txtOrderId.Text)
com.Parameters.AddWithValue("#OrderStatus", "Pending")
Dim sqladapter As New MySqlDataAdapter(com)
sqladapter.Fill(dt)
If dt.Rows.Count Then
GridView1.DataSource = dt
GridView1.DataBind()
Else
Label1.Text = "Order ID Doesn't Exist"
End If
Lets take your sample and modify it:
query = "select FoodName, Qty, IngredientName, Quantity, OrderStatus
from tblorder, tblorderdetail, tblfood, tblcustomizefooddetail, tblcustomizeingredient, tblordercustomize
where tblOrder.OrderId = #OrderId and OrderStatus = #OrderStatus and tblorder.OrderId = tblorderdetail.OrderId and tblorderdetail.FoodId = tblfood.FoodId and tblorderdetail.OrderDetailId = tblordercustomize.OrderDetailId and tblfood.FoodId = tblcustomizefooddetail.FoodId and tblcustomizeingredient.IngredientId = tblcustomizefooddetail.IngredientId and tblordercustomize.IngredientId = tblcustomizeingredient.IngredientId"
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("#OrderId", txtOrderId.Text)
com.Parameters.AddWithValue("#OrderStatus", "Pending")
Dim adapter as new SqlDataAdapter(com)
adapter.Fill(dt)
if adapter.Tables(0).Rows.Count > 0
GridView1.DataSource = adapter.Tables(0)
GridView1.DataBind()
Else
Label1.Text = "Order ID Doesn't Exist"
End If

output parameter into label

instead of returning my output paremeter value in my stored procedure to my label it returns the default value i set my output parameter to.
why cant i put my output parameter into my text label
Dim reader As SqlDataReader
cmd.Parameters.AddWithValue("#tour", "2365")
cmd.Parameters.Add("#tourname", SqlDbType.VarChar)
cmd.Parameters("#tourname").Direction = ParameterDirection.Output
cmd.CommandText = "test"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = conn
conn.Open()
reader = cmd.ExecuteReader()
Dim myTable As DataTable = New DataTable()
myTable.Load(reader)
DropDownList1.DataSource = myTable
DropDownList1.DataTextField = "ddate7"
DropDownList1.DataBind()
Label1.Text = cmd.Parameters("#tourname").ToString
conn.Close()
You haven't defined the #tourname parameter as an output parameter.
Dim param as New SqlParameter("tourname", 2356)
param.Direction = ParameterDirection.Output
cmd.Parameters.Add(param)

Resources