Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
any one can help me out from this logic error

this code can't show the data in the output
dbp = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Documents\mydata.mdb;User Id=admin;Password=;"
        con.ConnectionString = dbp
        con.Open()


        sql = "select * from test";
        
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "mydata")
        MsgBox("Database is now Open")

        con.Close()
        MsgBox("Database is Now Closed")




[Edited]code is wrapped in "pre" tags[/Edited]
Posted
Updated 29-Dec-10 3:37am
v3
Comments
Dr.Walt Fair, PE 24-Dec-10 1:27am    
I see no output, other than the MsgBox's. Is it a problem with the connection or the query or something else?
Tarun.K.S 24-Dec-10 1:27am    
Where do you want the output? You are just filling the dataset.
yaprig 24-Dec-10 2:25am    
Do you want to insert value from textbox to database or from database to textbox??

I can't see error in that code but I can see some bad practice.

I mean.

If you're using DataAdapter then no need to close connection, DataAdapter will be fully responsible for that.

Data Will be filled when you are calling da.Fill(ds,"mydata");
After that Database connection will be closed. and you stated that "Database is now open" and Further you closed again connection which is already closed.

For safe side to close connection you should use.

if (con.State == ConnectionState.Open)
 con.close();
 
Share this answer
 
Comments
Tarun.K.S 24-Dec-10 2:50am    
Also ds(dataset) has also not been declared.
Mudasar Ahmad 24-Dec-10 5:56am    
thank
Well, the above code just brings data from database and fills it in a dataset. Nothing else. You put a messagebox to display some message. There is no code written to display the data fetched.

As correctly said, it's a logical error in understanding. If you need to see the data fetched then for sample, place a grid on the page and then bind the dataset fetched to this grid. Data retrieved would be visible in this grid.
 
Share this answer
 
Comments
Mudasar Ahmad 24-Dec-10 5:56am    
thank yaar i have logical error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900