Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
 
        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
 
        cmd.CommandText = "select * from Table1"
 
<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 31-Mar-13 14:10pm
anamo321
Edited 31-Mar-13 14:15pm
v2
Comments
ThePhantomUpvoter at 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 at 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
ThePhantomUpvoter at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can use the code bellow to populate the data grid
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
  Permalink  
Comments
anamo at 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)

  Print Answers RSS
0 OriginalGriff 386
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 215
3 /\jmot 189
4 Praneet Nadkar 173
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 1 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100