Link to home
Create AccountLog in
Avatar of Cannibal_Jack
Cannibal_Jack

asked on

Convert some code in C# to VB.Net

Hi, I've found a site that has the answer to my problem which is connecting my autocomplete for a textbox to a sql database source. Here's the site...
http://www.c-sharpcorner.com/UploadFile/asif.blog/WinAutoComplete01162007163259PM/WinAutoComplete.aspx

The problem is that the code is written in C# and I need it in visual basic, would anyone be able to help convert it to visual basic for me?

It's just this part I could do with help for...

            //declare connection string
            string cnString = @"Data Source=(local); Initial Catalog=northwind;" +
            "User Id=northwind;Password=northwind";
            /*use following if you use standard security
           string cnString = @"Data Source=(local);Initial
            Catalog=northwind; Integrated Security=SSPI"; */
            //declare Connection, command and other related objects
            SqlConnection conGetData = new SqlConnection(cnString);
            SqlCommand cmdGetData = new SqlCommand();
            SqlDataReader drGetData;
            try
            {
                //open connection
                conGetData.Open();
               //prepare connection object to get the data through
                //reader and populate into dataset
                cmdGetData.CommandType = CommandType.Text;
                cmdGetData.Connection = conGetData;
                cmdGetData.CommandText = "Select ProductName From Products";
                //read data from command object
                drGetData = cmdGetData.ExecuteReader();
                if (drGetData.HasRows == true)
                {
                    while (drGetData.Read())
                        ProductList.Add(drGetData["ProductName"].ToString());
                }
                else
                    MessageBox.Show("No data found in Products tables");
                //close reader and connection
                drGetData.Close();
                conGetData.Close();

Any help would be great, thanks.
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Cannibal_Jack
Cannibal_Jack

ASKER

Thanks, Advice from you all was spot on.