<script language="VB" runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim costcenter As String = Session("costcenter") lbl1.Text = costcenter If lbl1.Text = "12941" Then Dim strSQL As String Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Integrated Security=SSPI;" & "Initial Catalog=TestSQL") strSQL = "SELECT * FROM [tblTrainingPlan] WHERE ([CostCenter] = @CostCenter)" connection.Open() Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection) GridView1.DataSource = myCommand.ExecuteReader() GridView1.DataBind() connection.Close() End If End Sub
Must declare the scalar variable "@CostCenter".
Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@CostCenter". Source Error: Line 14: connection.Open() Line 15: Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection) Line 16: GridView1.DataSource = myCommand.ExecuteReader() Line 17: GridView1.DataBind() Line 18: connection.Close() Source File: C:\Documents and Settings\oca14625\Desktop\WebSite3l\connectdatabase.aspx Line: 16
myCommand.Parameters.AddWithValue("@CostCenter", [value of your cost center])
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)