Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 697
  • Last Modified:

Conver c# code into vb.net

convert the following C#.net code into vb.net

[WebMethod]

    public CascadingDropDownNameValue[] GetProductsByCategoryID(string knownCategoryValues, string category)
    {
        string connectionString = SqlConnectionString.GetConnectionString();        
        string[] categoryValues = knownCategoryValues.Split(':', ';');
        int categoryID = Convert.ToInt32(categoryValues[1]);

        SqlConnection myConnection = new SqlConnection(connectionString);
        SqlCommand myCommand = new SqlCommand("SELECT ProductID, ProductName FROM Products WHERE CategoryID = @CategoryID", myConnection);
        myCommand.Parameters.AddWithValue("@CategoryID", categoryID);

        SqlDataAdapter ad = new SqlDataAdapter(myCommand);
        DataSet ds = new DataSet();
        ad.Fill(ds);

        List<CascadingDropDownNameValue> cascadeCollection = new List<CascadingDropDownNameValue>();

        foreach (DataRow row in ds.Tables[0].Rows)
        {
            cascadeCollection.Add(new CascadingDropDownNameValue((string)row["ProductName"], row["ProductID"].ToString()));

        }
        return cascadeCollection.ToArray();


    }
0
devdept
Asked:
devdept
1 Solution
 
davidwainwrightCommented:
<WebMethod()> _
Public Function GetProductsByCategoryID(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
      Dim connectionString As String = SqlConnectionString.GetConnectionString()
      Dim categoryValues As String() = knownCategoryValues.Split(":"C, ";"C)
      Dim categoryID As Integer = Convert.ToInt32(categoryValues(1))

      Dim myConnection As New SqlConnection(connectionString)
      Dim myCommand As New SqlCommand("SELECT ProductID, ProductName FROM Products WHERE CategoryID = @CategoryID", myConnection)
      myCommand.Parameters.AddWithValue("@CategoryID", categoryID)

      Dim ad As New SqlDataAdapter(myCommand)
      Dim ds As New DataSet()
      ad.Fill(ds)

      Dim cascadeCollection As New List(Of CascadingDropDownNameValue)()

      For Each row As DataRow In ds.Tables(0).Rows

            cascadeCollection.Add(New CascadingDropDownNameValue(DirectCast(row("ProductName"), String), row("ProductID").ToString()))
      Next
      Return cascadeCollection.ToArray()


End Function
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now