Passing value in a stored procedure using ASP.NET
Hello to all.. When my web form runs it asks for project code from the anonymous user, on entering that code the value is passed via session variable to a local variable which then checks that value with the records in the database,the local variable is passed in an adhoc query. After making a connection with Sql server. Now, i want to pass the same value in a stored procedure. I know
for that i have to take a @variable but how should i pass the value of
the mcode variable in that stored procedure.
Dim myQry1 As String = "exec gridreport"
Dim MCode As String
If Session("UserLogedIn") = "Yes" Then
MCode = Session("ProjectCode")
End If
If e.Item.ItemType = ListItemType.Footer Then
Dim myCon1 As New SqlConnection("data source=.;user id=sa;password=;initial catalog=hb")
myCon1.Open()
Dim myQry1 As String = "select sum(b.Onsite) as onsite,sum(b.Offshore) as offshore,sum(b.Offon) as offon,sum(b.Onsite+b.Offshore+b.Offon) as Total,sum(b.Revenue) as revenue from Projmaster a,Projslave b where a.P_Id=b.P_Id and a.M_Code='" & MCode & "'"
'Dim myQry1 As String = "exec gridreport" (how should i pass MCode value to this stored procedure)
Dim myDa1 As New SqlDataAdapter(myQry1, myCon1)
Dim myDS1 As New DataSet
dg_summary.DataSource = myDS1.Tables("adc")
Dim myCmd As New SqlCommand(myQry1, myCon1)
Dim myDR As SqlDataReader = myCmd.ExecuteReader
If myDR.Read Then
e.Item.Cells(3).Text = myDR.GetInt32(0)
e.Item.Cells(4).Text = myDR.GetInt32(1)
e.Item.Cells(5).Text = myDR.GetInt32(2)
e.Item.Cells(6).Text = myDR.GetInt32(3)
e.Item.Cells(7).Text = myDR.GetInt64(4)
'e.Item.Cells(6).Text = myDR.GetInt32(4)
'e.Item.Cells(7).Text = myDR.GetInt64(5)
End If
End If
|