|
-
Oct 17th, 2003, 03:33 PM
#1
Thread Starter
New Member
combo boxes and datasources???
I am using VB.NET and SQL Server. I have created a store procedure (getcompany) in SQL Server that gets one column of information from a table. i was to link this store procedure outcome to a combo box in a form. This is the code to get the store procedure:
Dim strcon As String = "data
source=BFS1;database=BS2;uid=sa;pwd=vonag340;"
Dim myadapter As New SqlClient.SqlDataAdapter("getcompany", strcon)
Dim ds As New DataSet
myadapter.SelectCommand.CommandType = CommandType.StoredProcedure
myadapter.Fill(ds, "output")
how do i link this to combobox1???
Thanks
-
Oct 17th, 2003, 05:25 PM
#2
PowerPoster
NEVER EVER EVER post your connection string with a username and password in it.
-
Oct 20th, 2003, 07:40 AM
#3
Thread Starter
New Member
I changed the info before i pasted it. Thanks for the advise, but i already figured that one out. Does anyone know how i can attach my store procedure as a datasource for a combobox???
-
Oct 20th, 2003, 08:58 AM
#4
Frenzied Member
This is C#, but it should give you an idea how to do it.
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
string ConnectionString = "server=localhost;user id=username;password=password;database=dbname";
SqlConnection Conn = new SqlConnection(ConnectionString);
SqlCommand Comm = new SqlCommand(getCompany, Conn);
SqlDataReader reader;
try
{
Conn.Open();
reader = Comm.ExecuteReader();
while(reader.Read())
{
ComboBox1.Items.Add(reader["CompanyName"]);
}
reader.Close();
Conn.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
}
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|