Visual Basic Datalistview

I have a datagridview1, and when a user clicks on a combo box options I would like the datagridview to change it's data using local database. Can't seem to get it to work correctly.


DataGridView1.DataSource = IctpcDataSet.ictpcdb.Load(SqlDataReader)

Open in new window

LVL 1
Jack_JonesAsked:
Who is Participating?
 
CodeCruiserCommented:
>AttachDbFilename=|DataDirectory|\ICT DB\ictpc.mdf

Try replacing that with a hardcoded path to the file
0
 
Jack_JonesAuthor Commented:
Tried this to,

IctpcDataSet.ictpcdb.Load(DataGridView1.DataSource)
            DataGridView1.Refresh()

Open in new window

0
 
CodeCruiserCommented:
>I would like the datagridview to change it's data using local database.
Not sure what you mean.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Jack_JonesAuthor Commented:
I have a .mdf file, when user selects let say 1, 2 or 3, it will load db1 for 1, db2 for 2, db3 for 3 into the datagridview1.
0
 
Jack_JonesAuthor Commented:
Only difference is I just want it to import everything in the db to the datagridview1
0
 
CodeCruiserCommented:
You would need to change the connection string of your connection and refill the grid.
0
 
Jack_JonesAuthor Commented:
how do i find my connection string?
0
 
CodeCruiserCommented:
So you used the wizard to create a typed dataset?
0
 
Jack_JonesAuthor Commented:
Data Source=.\SQLEXPRESS;AttachDbFilename="|DataDirectory|\ICT DB\ictpc.mdf";Integrated Security=True;User Instance=True


That long thing ^
0
 
Jack_JonesAuthor Commented:
I think it's getting somewhere,

error: Could not find installable ISAM.

on: adapter.fill(ds)
0
 
CodeCruiserCommented:
Hmm. What connection string did you use with adapter?
0
 
Jack_JonesAuthor Commented:
Connection String

Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ICT DB\ictpc.mdf" + ";Persist Security Info=False"

Open in new window

0
 
Jack_JonesAuthor Commented:
Here is what im working with,


im connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ICT DB\ictpc.mdf" + ";Persist Security Info=False"
        Dim conn As New OleDb.OleDbConnection(connectionstring)

        Dim adapter As New OleDb.OleDbDataAdapter("select * from ictpcdb", conn)
        'create a new dataset
        Dim ds As New DataSet
        'fill dataset
        adapter.Fill(ds)

        'attatch dataset to datagrid
        DataGridView2.DataSource = ds.Tables("tblFinal").DefaultView

Open in new window

0
 
CodeCruiserCommented:
Dont use Jet with SQL Server.

Use SQLDataAdapter and following connection string format

Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
0
 
Jack_JonesAuthor Commented:
can you help me construct what that would look like plz.
0
 
Jack_JonesAuthor Commented:
Ok here is what I have so far,

gives me an error with directory lookup for the file c:\program\ict db\ictpc.mdf failed with operating system error 5 ( Access is Denied )

Dim connectionstring As String = "Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\ICT DB\ictpc.mdf;Database=ictpc; Trusted_Connection=Yes"
        Dim dbadp As New SqlDataAdapter("Select * From ictdbpc", connectionstring)
        Dim dTable As New DataTable

        dbadp.Fill(dTable)
        'create a new dataset
        Dim ds As New DataSet
        'fill dataset
        'attatch dataset to datagrid
        DataGridView2.DataSource = dTable

Open in new window

0
 
CodeCruiserCommented:
Dim dbadp As New SQLDataAdapter("Select * from tablename", "Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;")

'Replace tablename, dbname, and dbfilename above

Dim dTable As New DataTable

dbadp.Fill(dTable)
dbadp.Dispose()
0
 
CodeCruiserCommented:
Are you on win7/vista with UAC on?
0
 
Jack_JonesAuthor Commented:
windows 7 with UAC
0
 
CodeCruiserCommented:
Try disabling the UAC.
0
 
Jack_JonesAuthor Commented:
Same error when I test run the app on windows xp machine.
0
 
Jack_JonesAuthor Commented:
The database might be looking for a username / password that I didn't setup...
0
 
CodeCruiserCommented:
Is your SQL Server using Windows Authentication or SQL Server authentication? If SQL Server, then supply the username and password as well in connection string.
0
 
Jack_JonesAuthor Commented:
windows auth
0
 
Jack_JonesAuthor Commented:
Got it to work! :) had to delete the .ldf file for some reason and it worked great.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.