Problem with 'must declare the scalar variable'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • verian
    New Member
    • Jan 2010
    • 3

    Problem with 'must declare the scalar variable'

    I'm currently making a front end to display license information for my companies software audit but im no pro with sql or asp.net so iv ran into a bit of trouble. I'm trying to get a sum of how many licenses there are across several rows so i can put it in a text box, but im getting the error 'Must declare the scalar variable "@softwareI D".'


    Code:
    SqlConnection con1 = Connect.GetSQLConnection();
            string dataEntry = softwareInputTxt.Text;
            string result;
    
            dataEntry = dataEntry + "%";
    con1.Open();
            SqlCommand Mycmd1;
            Mycmd1 = new SqlCommand("select sum(license_quantity_owned) from licenses where software_ID like @softwareID", con1);
            MyCmd.Parameters.AddWithValue("@softwareID", dataEntry);
            result = (string)Mycmd1.ExecuteScalar();
            licenseOwnedTxt.Text = result;
    Could anyone point me in the right direction?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Until someone with more experience can offer more targeted advice I can point you toward these:

    Database How-to parts 1 and 2
    Database tutorial Part 1
    Database tutorial Part 2

    Comment

    • krisviswa
      New Member
      • Mar 2010
      • 6

      #3
      Delaration of parameter looks to be missing before use . A vb snippet is as under where in you have to declare new sql parameter along with type

      Dim paramPwd As SqlParameter
      paramPwd = New SqlParameter("@ Password", SqlDbType.Binar y, 16)
      MyCmd.Parameter s.Add(paramPwd)

      Hope this helps
      kris

      Comment

      • krisviswa
        New Member
        • Mar 2010
        • 6

        #4
        In third line of code you may add parameter with value or you can add value in a separate line
        kris

        Comment

        Working...