Help with TableAdapter in VB Express

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hi,
I'm trying to fill a combobox with values from a sql table. Data
seems to be connected fine. Apparently in VB Express sqlDataAdapter
doesn't work, or at least I can't make it work. Searching the help
information, it directed me to Table Adapters instead.

Can anybody help me with correcting this code. It doesn't like the
sql statement at the end of table adapters declaration line. How do I
get a sql statement to populate table values so that I can direct them
to the combobox?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.PublishersTableAdapter.Fill(Me.PUBSDataSet.publishers)

Dim PubsDS As New PUBSDataSet()
Dim PubsTA As New
PUBSDataSetTableAdapters.publishersTableAdapter()= ("SELECT * FROM
publishers")

PubsTA.Fill(PubsDS.publishers)

cboPubID.DataSource = PubsDS
cboPubID.ValueMember = "pub_id"
cboPubID.DisplayMember = "pub_name"

Thanks,
Randy
 
table adapters are unnecessary

ADO.net is hogwash

stick with ADO classic, write data in HTML and don't follow the trendy
'programming language of the month' paradigm
 
I am not a troll

I just speak for truth

Jihad against Microsoft; not all change is good
not all change is trendy

I won't change languages 'just because it's trendy thing to do'
 
Table adapters are used with strongly typed datasets. You design these
through the Data Designer. That doesn't seem like what you are doing. It
sounds like you just want to read the database, get a table of data, and
bind it to your combobox. Is that right?

If so, try something like this:

Dim dt as DataTable

Using cn as New SqlConnection(myConnectionString)

cn.Open()

'Define the SQL Command object
Dim cmd As SqlCommand = New SqlCommand()
cmd.Connection = cn
cmd.ComandType = CommandType.Text
cmd.CommandText = ""SELECT * FROM publishers"

Dim da As SqlDataAdapter = new SqlDataAdapter(cmd)
dt = New DataTable()
da.Fill(dt)

End Using 'This closes the connection

cboPubID.DataSource = dt
cboPubID.ValueMember = "pub_id"
cboPubID.DisplayMember = "pub_name"

Robin S.
 
wow... that is funny

do you know how many lines of code it takes me to build a databound
combo box?

UH ZERO?
 
Back
Top