locked
trying to rewrite a small C# function to vb.net. Need help please? RRS feed

  • Question

  • User210228557 posted

    Can someone help me rewrite this c# code to vb.net? I think I have most of it right but I am stuck.

       
       [WebMethod]
    public string[] GetCountryInfo(string prefixText)
    {
    int count = 10;
    string sql = "Select * from customer Where company like @prefixText";
    SqlDataAdapter da = new SqlDataAdapter(sql,"Data Source=MISFS;Initial Catalog=QuoteSystem;Integrated Security=True");
    da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 255).Value = prefixText+ "%";
    DataTable dt = new DataTable();
    da.Fill(dt);
    string[] items = new string[dt.Rows.Count];
    int i = 0;
    foreach (DataRow dr in dt.Rows)
    {
      items.SetValue(dr["company"].ToString(),i);
      i++;
    }
    return items;


    }

      
       <WebMethod()> _
       Public Shared Function GetNameList(ByVal prefixText As String, ByVal count As Integer) As String()
            Dim items As String
            Dim conn As New Data.SqlClient.SqlConnection
            Dim SQL As String
    
            count = 10
    
            SQL = "SELECT company FROM customer WHERE company LIKE '" & prefixText & "%'"
            Dim da As SqlDataAdapter = New SqlDataAdapter(SQL, "GetConnectionString")
            da.SelectCommand.Parameters.Add("@prefixtext", SqlDbType.VarChar, 255).Value = prefixText + "%"
    
            Dim dt As DataTable = New DataTable
            da.Fill(dt)
    
            Dim dr As DataRow
            Dim i As Integer = 0
            For Each dr In dt.Rows
    
            Next
    
            items = dt.Rows.Count
            i = i+
    
            Return items
        End Function
     
    Tuesday, April 8, 2008 12:20 PM

Answers

  • User397347636 posted
    <WebMethod> _
    Public Function GetCountryInfo(ByVal prefixText As String) As String()
    	Dim count As Integer = 10
    	Dim sql As String = "Select * from customer Where company like @prefixText"
    	Dim da As New SqlDataAdapter(sql,"Data Source=MISFS;Initial Catalog=QuoteSystem;Integrated Security=True")
    	da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 255).Value = prefixText & "%"
    	Dim dt As New DataTable()
    	da.Fill(dt)
    	Dim items(dt.Rows.Count - 1) As String
    	Dim i As Integer = 0
    	For Each dr As DataRow In dt.Rows
    		items.SetValue(dr("company").ToString(),i)
    		i += 1
    	Next dr
    	Return items
    End Function
    

    (Instant VB)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 8, 2008 6:12 PM

All replies

  • User-417784260 posted

     The c# function was using a parameter

            SQL = "SELECT company FROM customer WHERE company LIKE @prefixText'"
    Dim da As SqlDataAdapter = New SqlDataAdapter(SQL, "
    GetConnectionString")
    da.SelectCommand.Parameters.Add("
    @prefixtext", SqlDbType.VarChar, 255).Value = prefixText & "%"
    Tuesday, April 8, 2008 1:27 PM
  • User397347636 posted
    <WebMethod> _
    Public Function GetCountryInfo(ByVal prefixText As String) As String()
    	Dim count As Integer = 10
    	Dim sql As String = "Select * from customer Where company like @prefixText"
    	Dim da As New SqlDataAdapter(sql,"Data Source=MISFS;Initial Catalog=QuoteSystem;Integrated Security=True")
    	da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 255).Value = prefixText & "%"
    	Dim dt As New DataTable()
    	da.Fill(dt)
    	Dim items(dt.Rows.Count - 1) As String
    	Dim i As Integer = 0
    	For Each dr As DataRow In dt.Rows
    		items.SetValue(dr("company").ToString(),i)
    		i += 1
    	Next dr
    	Return items
    End Function
    

    (Instant VB)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 8, 2008 6:12 PM