Results 1 to 4 of 4

Thread: combo boxes and datasources???

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    9

    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

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    NEVER EVER EVER post your connection string with a username and password in it.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    9
    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???

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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
  •  



Click Here to Expand Forum to Full Width