phreaky Posted April 1, 2004 Posted April 1, 2004 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??? Quote tHe pHrEaKy
Arch4ngel Posted April 1, 2004 Posted April 1, 2004 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" Quote "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
phreaky Posted April 1, 2004 Author Posted April 1, 2004 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? Quote tHe pHrEaKy
phreaky Posted April 1, 2004 Author Posted April 1, 2004 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 "=" Quote tHe pHrEaKy
Arch4ngel Posted April 1, 2004 Posted April 1, 2004 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 ;) Quote "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
Administrators PlausiblyDamp Posted April 1, 2004 Administrators Posted April 1, 2004 Have you tried SELECT * FROM Car WHERE Name_car LIKE '%" & TextBox1.Text & "%'" If not what text does the message box display? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
phreaky Posted April 2, 2004 Author Posted April 2, 2004 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 Quote tHe pHrEaKy
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.