Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2015
    Messaggi
    12

    Apertura database access da un altro form visual basic (visual studio express 2012)

    ciao a tutti,
    ho un problema con i database, ho due form, uno principale(form1) e uno (form2) che ha un datagridview per visualizzare il db in access.

    Dal form1 schiacciando un pulsante devo aprire il form2, lo faccio ma non mi visualizza nel datagridview il db.

    grazie per l'aiuto

  2. #2
    Quote Originariamente inviata da crobs Visualizza il messaggio
    ciao a tutti,
    ho un problema con i database, ho due form, uno principale(form1) e uno (form2) che ha un datagridview per visualizzare il db in access.

    Dal form1 schiacciando un pulsante devo aprire il form2, lo faccio ma non mi visualizza nel datagridview il db.

    grazie per l'aiuto
    se non posti il codice che hai fatto, è difficile che qualcuno che ti riesca ad aiutare....
    Ultima modifica di fermat; 12-10-2015 a 16:06

  3. #3
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,304
    Visual Basic, inoltre, ha un forum dedicato.

    Sposto.

    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  4. #4
    Utente di HTML.it
    Registrato dal
    Oct 2015
    Messaggi
    12
    ok

    il form1:

    Private Sub Button1_Click( sender As Object, e As EventArgs) Handles Button1.Click
    My.Forms.Database_Win.Show()
    End Sub

    form2:

    Public Class Database_Win




    Private Sub Database_Win_Load( sender As Object, e As EventArgs) Handles MyBase.Load


    If My.Computer.FileSystem.FileExists("C:\Users\....ac cdb") Then
    MsgBox(" Database found ", MsgBoxStyle.Information, " Information ")
    Else
    Try
    MsgBox(" Database not found ", MsgBoxStyle.Exclamation, " Attention ")
    My.Computer.FileSystem.CopyFile(
    "C:\Users\....accdb",
    "C:\Users\....accdb")
    ' db back up is upload
    MsgBox(" Loaded database ", MsgBoxStyle.Information, " Information ")
    Catch ex As Exception
    MsgBox(" The database doesn't exist or can't be loaded ", MsgBoxStyle.Critical, " Attention ")
    Me.Close()
    End Try
    End If


    Me.Table1TableAdapter.Fill(Me.VbAccess2007DataSet. Table1)

    With DataGridView1
    .ClearSelection()
    .ReadOnly = True
    .Multiselect = False
    End With



    Me.reset()

    End Sub


    ' Previous btn
    Public Sub Previous_btn_Click( sender As Object, e As EventArgs) Handles Previous_btn.Click
    Table1BindingSource.MovePrevious()
    End Sub


    ' Add New btn
    Public Sub AddNew_btn_Click( sender As Object, e As EventArgs) Handles AddNew_btn.Click
    Table1BindingSource.AddNew()
    End Sub


    ' Next btn
    Public Sub Next_btn_Click( sender As Object, e As EventArgs) Handles Next_btn.Click
    Table1BindingSource.MoveNext()
    End Sub


    ' Save btn
    Public Sub Save_btn_Click( sender As Object, e As EventArgs) Handles Save_btn.Click
    Try
    ' On Error Goto SaveErr
    Table1BindingSource.EndEdit()
    Table1TableAdapter.Update(VbAccess2007DataSet.Tabl e1)
    MsgBox(" Save OK ", MsgBoxStyle.Information, " Information ")
    Catch ex As Exception
    MsgBox(" Don't Save ", MsgBoxStyle.Exclamation, " Information ")
    End Try


    End Sub


    ' Delete btn
    Public Sub Delete_btn_Click( sender As Object, e As EventArgs) Handles Delete_btn.Click
    If Table1BindingSource.Count <> 0 Then
    If MsgBox(" Are you sure to delete ? ", MessageBoxButtons.YesNo + MsgBoxStyle.Exclamation, " Delete record ") = DialogResult.Yes Then
    Table1BindingSource.RemoveCurrent
    Else
    Exit sub
    End If
    Else
    MsgBox(" Delete isn't possibile because there aren't records ", MsgBoxStyle.Information, " Information ")
    Exit sub
    End If

    End Sub


    ' Close btn
    Public Sub Close_btn_Click( sender As Object, e As EventArgs) Handles Close_btn.Click
    If MsgBox(" Are you sure to Exit ? ", MessageBoxButtons.YesNo + MsgBoxStyle.Question, " Exit database ") = DialogResult.Yes Then
    End
    End If
    End Sub


    ' Update btn
    Public Sub Update_btn_Click( sender As Object, e As EventArgs) Handles Update_btn.Click
    Try
    Table1BindingSource.EndEdit()
    Table1TableAdapter.Update(VbAccess2007DataSet.Tabl e1)
    MsgBox(" Update OK ", MsgBoxStyle.Information, " Information ")
    Catch ex As Exception
    MsgBox(" Don't Update ", MsgBoxStyle.Exclamation, " Information ")
    End Try


    End Sub




    ' Search btn
    Public Sub Search_btn_Click( sender As Object, e As EventArgs) Handles Search_btn.Click
    On Error Goto SearchErr


    If txtSearch.Text = "" then
    Call notFound()
    Exit Sub
    Else
    Dim cantFind As String = txtSearch.Text
    Me.dvgFill()


    Table1BindingSource.Filter = "(Convert(ID, 'System.String') LIKE '" & txtSearch.Text & "')" & _
    "OR (Stocknum LIKE '" & txtSearch.Text & "')" & _
    "OR (Serialnum LIKE '" & txtSearch.Text & "')" & _
    "OR (Convert(Testcellnum, 'System.String') LIKE '" & txtSearch.Text & "')"


    If Table1BindingSource.Count <> 0 Then
    With DataGridView1
    .DataSource = Table1BindingSource
    End With
    Else
    Me.notFound()

    MsgBox("--> " & cantFind & vbNewLine & " The search item was not found. ", MsgBoxStyle.Information, " Error! ")

    Table1BindingSource.Filter = Nothing


    With DataGridView1
    .ClearSelection()
    .ReadOnly = True
    .MultiSelect = False
    .DataSource = Table1BindingSource
    End With
    End If
    End If


    ErrExit:
    Exit Sub
    SearchErr:
    MsgBox(" Error Number " & Err.Number & vbNewLine & " Error Description " _
    & Err.Description, MsgBoxStyle.Critical, " Reset Error! ")
    Resume ErrExit
    End Sub




    ' Reset function
    Public Sub reset()
    Dim txts As TextBox = txtSearch
    With txtSearch
    .Text = ""
    .Select()
    End With


    If DataGridView1.DataSource is Nothing Then
    Exit Sub
    End If

    End Sub


    ' notFound function
    Public Sub notFound()

    Dim txtS As TextBox = txtSearch
    With txtS
    .Select()
    .SelectAll()
    End With


    If DataGridView1.DataSource is Nothing Then
    Exit Sub
    End If






    End Sub

    End Class

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.