March 17, 2009 at 12:34 pm
Hi everyone,
My first post here. I hope I'm not too much of a beginner. I just dove in with developing a Windows Form (to work on a local network). The drop down in the form needs to pull data from the SQL server database/table. I seem to have the connection right. I get the datasource and displaymember in the properties of the drop down. But the data just won't show. I'm sure it's so super simple but I can't get it. Any help please? (btw I'm using VS 2008 / C#) for dev.
Thanks much,
'Had
March 17, 2009 at 12:58 pm
Hi
A Form, a ComboBox, a Button:
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection cn = new SqlConnection(@"Server=YourServername;Database=AdventureWorks;User Id=YourUsername;Password=YourPassword;"))
{
cn.Open();
using (SqlDataAdapter adap = new SqlDataAdapter("SELECT TOP(100) FirstName FROM Person.Contact", cn))
{
DataTable dt = new DataTable();
adap.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "FirstName";
}
cn.Close();
}
}
This is a little more an C# issue than SQL ;-).
Greets
Flo
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply