Hi gokuldas,
Refer below sample.
You nee to select only two column you can't select multiple column for that reason text is not showing in combobox.
Refer below sample code.
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = GetData();
if (dt.Rows.Count > 0)
{
DataRow dr = dt.NewRow();
dr[0] = 0;
dr[1] = "All";
dt.Rows.InsertAt(dr, 0);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "Country";
comboBox1.ValueMember = "CustomerId";
}
}
public DataTable GetData()
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT CustomerId,Country FROM Customers", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
}
}
VB.Net
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = New DataTable()
dt = GetData()
If dt.Rows.Count > 0 Then
Dim dr As DataRow = dt.NewRow()
dr(0) = 0
dr(1) = "All"
dt.Rows.InsertAt(dr, 0)
comboBox1.DataSource = dt
comboBox1.DisplayMember = "Country"
comboBox1.ValueMember = "CustomerId"
End If
End Sub
Public Function GetData() As DataTable
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT CustomerId,Country FROM Customers", con)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
Return dt
End Using
End Using
End Using
End Function
Screenshot