Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I've learned how to access a (MSACCESS) database, I've made the OleDBConnection, the OleDbAdapter and the Dataset, this last one just makes a "SELECT * FROM Cars", now, I've made a DataGrid and it recognizes the columns from my DB (just the columns number and its titles), but it doesn't fill the data contained in the DB (it's already filled, I mean, the DB it's not empty), I thought that the DataSet could work just like VB6 where you just change the SQL Command property of the ADO, changing the <<OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM Cars WHERE Car_name = 'Accent'">>, it didn't work after a DataGrid.Refresh, it keeps (all the time displaying "null") on all its columns filling.

 

So, I know now that the Datagrid is the problem here, because I don't know how to fill it with the info we could get through the OleDbAdapter and its Dataset...how do I make a connection between the DataGrid and the info I'm looking for from the OleDbAdapter???

tHe pHrEaKy
Posted

first... you must fill your DataSet with the Adapter

 

adap.Fill( ds.Cars )

And if your DataSource and DataMember are set at design... everything should work

 

If not...

  datagrid.DataSource = ds
  datagrid.DataMember = "Cars"

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
first... you must fill your DataSet with the Adapter

 

adap.Fill( ds.Cars )

And if your DataSource and DataMember are set at design... everything should work

 

If not...

  datagrid.DataSource = ds
  datagrid.DataMember = "Cars"

 

Perfectly, that worked, GEZ!, completely different from VB6, huh?

tHe pHrEaKy
Posted

Well it seems the problem goes another level...here's the fragment of the code that gives me problems now:

 

OleDbDataAdapter1.SelectCommand.CommandText = _

"SELECT * FROM Carro WHERE Name_car = '%" & TextBox1.Text & "%'"

MsgBox("SELECT * FROM Car WHERE Name_car LIKE '%" & TextBox1.Text & "'")

DataGrid1.ResetText()

DataSet11.Clear()

OleDbDataAdapter1.Fill(DataSet11.Carro)

DataGrid1.Refresh()

 

 

Now, this is working ONLY if I don't add the two "%", but when you add them...the code doesn't work...I mean, it must show two items in the DB: one called "Tiburon" and the other one called "Tiburon FX" however it doesn't show anyone. I don't see any mistake in the sentence or the sintaxis...so, what is it???

 

PS: I already tried LIKE instead of "="

tHe pHrEaKy
Posted

OleDbDataAdapter1.SelectCommand.CommandText = _
"SELECT * FROM Carro WHERE Name_car [b]Like[/b] '%" & TextBox1.Text & "%'"
MsgBox("SELECT * FROM Car WHERE Name_car LIKE '%" & TextBox1.Text & "'")
[b]'DataGrid1.ResetText()
[/b]DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11.Carro)
[b]'DataGrid1.Refresh() // I even think it's not necessary
[/b]

 

Bold lines are where I maked some modifications. Don't need to refresh it in my last memory. or do a simple .DataSource = .... If you want a "like" write it in your SQL-Statement ;)

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
Have you tried

SELECT * FROM Car WHERE Name_car LIKE '%" & TextBox1.Text & "%'"

 

If not what text does the message box display?

 

After posting my message I just did what the other message recommended and it worked....the MsgBox was just a "flag" for myself to see that I was doing the right SQL command, I forgot to take it out, sorry :P

tHe pHrEaKy

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...