Hi
When i binding combobox no any values display, my code is :
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = con;
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "select name_of_party from client_master";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
combo_nameofparty.DataSource = ds.Tables["client_master"];
combo_nameofparty.DisplayMember = "name_of_party";
combo_nameofparty.ValueMember = "name_of_party";
con.Close();
Loading
Blocked AccountPosted Dec 12, 2011, 7:44 AM
you have created cmd1 variable of SqlCommand and you are passing cmd in the below statement. I think this is the reason.
SqlDataAdapter da = new SqlDataAdapter(cmd);
I checked your code and it's working fine.
SqlConnection con = new SqlConnection("server=serverName;uid=manish;pwd=manish;database=TestDB;");
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = con;
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "select top 5 FirstName from userregistration" ;
SqlDataAdapter da = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
con.Open();
da.Fill(ds);
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "FirstName";
comboBox1.ValueMember = "FirstName";
Satyapriya NayakPosted Dec 12, 2011, 7:45 AM
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Datagridview_bind
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from customer";
com = new OleDbCommand(str, con);
oda = new OleDbDataAdapter(com);
ds = new DataSet();
oda.Fill(ds, "customer");
comboBox1.DataSource = ds.Tables["customer"];
comboBox1.DisplayMember = "custid";
comboBox1.ValueMember = "custid";
con.Close();
}
}
}
Thanks