Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 669183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:07:24+00:00 2026-05-14T00:07:24+00:00

Below is the code that I’m using in ms access to list the data

  • 0

Below is the code that I’m using in ms access to list the data according to what is selected in combobox and what is input in textbox.

My problem is there no commandbuilder in ms sql like in ms access, because it fails when I try:

dim mscombuilder as new sqlcommandbuilder

Here is the code:

''#list school
If ComboBox1.SelectedItem = "School" Then
    Dim connectionString As String = "Data Source=SENBONZAKURA\SQLEXPRESS;Initial Catalog=testing;User ID=SenbonZakura\Rew; Trusted_Connection=True;"

    Dim selectCommand As String
    Dim sqlcon As New SqlConnection(connectionString)

    selectCommand = "select * from student WHERE (SCHOOL='" & TextBox1.Text & "')"

    Me.dataAdapter = New OleDbDataAdapter(selectCommand, connection)
    Dim commandBuilder As New OleDbCommandBuilder(Me.dataAdapter)

    Dim table As New DataTable()   
    table.Locale = System.Globalization.CultureInfo.InvariantCulture

    Me.dataAdapter.Fill(table)  
    Me.BindingSource1.DataSource = table

    Dim data As New DataSet()  
    data.Locale = System.Globalization.CultureInfo.InvariantCulture

    DataGridView1.DataSource = Me.BindingSource1   
    Me.DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.White

    Me.DataGridView1.AutoResizeColumns( _
           DataGridViewAutoSizeColumnsMode.AllCells)

-There is no such thing as commandbuilder in the options that will appear. Do you know of any alternative of commandbuilder in ms sql?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:07:24+00:00Added an answer on May 14, 2026 at 12:07 am

    I hate to put you down like this, but there are just so many things wrong here:

    • You can’t mix the system.data.sqlclient classes and the system.data.oledb classes! Pick one provider or the other, not both.
    • SCHOOL='" & TextBox1.Text & "')" NEVER substitute user input directly into a query like that! It’s a major security hole. What if I enter ';DROP TABLE Student;-- into your TextBox1?
    • You don’t properly check that your connection will be closed. If an exception is thrown or anything else unexepected occurs it will be left open, eventually causes your database to choke.
    • Don’t set your bind your datasource to your grid until after you set styles for the grid. Otherwise you might end up drawing your grid twice.
    • Don’t hard-code your connection string in a local variable. At least factor it out into a common data layer somewhere.

    You want something more like this:

    ''#list schools
    If ComboBox1.SelectedItem = "School" Then
    
        Me.DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.White
        Me.DataGridView1.AutoResizeColumns( _
             DataGridViewAutoSizeColumnsMode.AllCells)
    
        Using cn As New SqlConnection(LoadConnectionStringFromConfigFile()), _
              cmd As New SqlCommand("SELECT * FROM Student WHERE School= @School")
    
            cn.Open()
            cmd.Parameters.AddWithValue("@School", TextBox1.Text)
    
            DataGridView1.DataSource = cmd.ExecuteReader()
    
            DataGridView1.DataBind() ''#ASP.Net only - don't do this line in winforms
        End Using
    

    And if you really want to do it right, you’ll factor out all code that talks to the database to a completely separate class, and then your databinding code is even simpler:

    ''#list schools
    If ComboBox1.SelectedItem = "School" Then
    
        Me.DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.White
        Me.DataGridView1.AutoResizeColumns( _
             DataGridViewAutoSizeColumnsMode.AllCells)
    
        DataGridView1.DataSource = MyDataClassVar.GetStudentsInSchool(TextBox1.Text)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 408k
  • Answers 408k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You must bind your list with data and ListMultipleChoice as… May 15, 2026 at 6:48 am
  • Editorial Team
    Editorial Team added an answer Check these functions: ReadProcessmemory WriteProcessmemory May 15, 2026 at 6:48 am
  • Editorial Team
    Editorial Team added an answer You'll want to place a transparent iframe over the object… May 15, 2026 at 6:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.