Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create small database and I want to show all information about the students that user
enter his Students ID I know that has some misktake but hope someone ill get help me to get trough this as its my fist project

I caret my database using visual studio 2008

screenshot

I think there is mistake at this statement

VB
cnn.ConnectionString = "Provider=localhost;data source=C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\APP V1.2\APP V1.2\DATABASE1.MDF"


and the other one at way of calling tried to change all (*) fields to select one column of my database but it still give all the data in my database

VB
cmd.CommandText = "select * from Table1"


VB
<pre lang="vb">Public Class Form1

    Dim cnn As OleDb.OleDbConnection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Database1DataSet2.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter1.Fill(Me.Database1DataSet2.Table1)
        'TODO: This line of code loads data into the 'Database1DataSet1.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter.Fill(Me.Database1DataSet1.Table1)
        cnn = New OleDb.OleDbConnection
        cnn.ConnectionString = "Provider=localhost;data source=C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\APP V1.2\APP V1.2\DATABASE1.MDF"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim cmd As OleDb.OleDbCommand

        If Not cnn.State = ConnectionState.Open Then
            cnn.Open()
        End If
        cmd.Connection = cnn
        cmd.CommandText = "select * from Table1"
        cmd.ExecuteNonQuery()

    End Sub
End Class
Posted
Updated 31-Mar-13 13:15pm
v2
Comments
[no name] 31-Mar-13 19:54pm    
"data source=C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\APP V1.2\APP V1.2\DATABASE1.MDF" should probably be just "data source=DATABASE1" see www.connectionstrings.com
Your second statement that I guess is actually a question, it is not possible. You could not possibly change "select * from Table1" to "select column1 from table1" and get all of the data in your database unless you only had column1 in your database.
anamo 1-Apr-13 7:27am    
i tired what u said I keep get error message that says http://www.4shared.com/photo/cluDBGht/ewftsefwa.html
i tries this solution but not work out
http://www.codeproject.com/Questions/464072/The-Microsoft-Jet-OLEDB-4-0-provider-is-not-regist
and for the second answer I meant I did that just to test if my query work or not and i found it not work coz of the above error
[no name] 1-Apr-13 8:48am    
"http://www.4shared.com/photo/cluDBGht/ewftsefwa.html" is not an error message. And course is does not work if you cannot connect to your database. Until you describe the real problem I am afraid that you will not get much help/

1 solution

You can use the code bellow to populate the data grid
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim constr as new OleDb.OleDbConnection
constr.ConnectionString = "Provider=localhost;data source=C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\APP V1.2\APP V1.2\DATABASE1.MDF"
Dim sqlstr as string=""
sqlstr="select * from Table1 where StudentID=" & Textbox1.text

       Try
            Dim ds As New DataSet
            Dim apt As New SqlDataAdapter
            apt.Dispose()
            ds.Dispose()
            apt = New SqlDataAdapter(sqlstr, constr)
            apt.Fill(ds)
            Datagridview1.DataSource = ds.Tables(0)
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try 
End Sub
 
Share this answer
 
Comments
anamo 1-Apr-13 7:21am    
Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(selectCommandText As String, selectConnection As System.Data.SqlClient.SqlConnection)': Value of type 'System.Data.OleDb.OleDbConnection' cannot be converted to 'System.Data.SqlClient.SqlConnection'.
'Public Sub New(selectCommandText As String, selectConnectionString As String)': Value of type 'System.Data.OleDb.OleDbConnection' cannot be converted to 'String'. C:\Users\user\Documents\Visual Studio 2008\Projects\app v1.2\app v1.2\Form1.vb 30 19 app v1.2

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