Solution Guide 2:
Dim sql as String = "Select * From Company Where CompanyName=@CompanyName"
Dim objDA As System.Data.SqlClient.SqlDataAdapter = _
New System.Data.SqlClient.SqlDataAdapter(sql, connection)
objDA .Parameters.Add("@CompanyName", CompanyNameComoboBox.SelectedValue)
Dim objDS As New DataSet
Try
objDA.Fill(objDS, "CompanyData")
If objDS.Tables("CompanyData").Rows.Count = 0 Then
Messagebox.Show("No Entries Found")
Exit Sub
ElseIf objDS.Tables("CompanyData").Rows.Count >1 Then
Messagebox.Show("Results are not distinct!")
Exit Sub
EndIf
For Each dr As DataRow In objDS.Tables("CompanyData").Rows
txtCompanyCode.Text = dr ("CompanyCode").ToString()
txtCompanyAlias.Text = dr ("Alias").ToString()
txtAddress.Text = dr ("Address").ToString()
cmbCity.Text = dr ("city").ToString()
txtPincode.Text = dr ("Pincode").ToString()
cmbState.Text = dr ("State").ToString()
txtCountry.Text = dr ("Country").ToString()
txtPh1.Text = dr ("Ph1").ToString()
txtPh2.Text = dr ("Ph2").ToString()
txtPh3.Text = dr ("Ph3").ToString()
txtFax.Text = dr ("Fax").ToString()
txtMobile.Text = dr ("Mobile").ToString()
txtEmail.Text = dr ("Email").ToString()
txtWebsite.Text = dr ("Website").ToString()
Next
Catch ex As Exception
End Try
Things to check, which I do not know! What is the name of the combo box of company names called?
Change CompanyNameComoboBox to be that control's name
Also, is it actually displaying the name of the company in that combo box?
The SQL statement might be wrong because I do not know the column header you are searching on, so change that if it is different.
The premise of what I have defined here should work but will need some tweaking to your exact situation and without that knowledge I cannot do that bit.