Newsgroup: italia.napoli.discussioni
Titolo: Connection OleDb in vbnet

Tom � rimasto a piedi con il lavoro, questo � un pezzettino dell'ultimo
programmino che ho fatto...da solissimo ...in vbnet..
Connessione Oledb per utilizzare un db Access
prima avevo utilizzato la Imports System.Data.SqlClient
per il db sqlclient,
Tom ....si � fatto molti nemici....perch�????????....boooooo 
Imports System.Data.OleDb
Imports System.Diagnostics
Imports System.Configuration
Imports Utility
Imports System.Data
Partial Class _Default
    Inherits 
System.Web.UI.Page
    Public Data As String
    Public Ora As String
    Public CodConcess As Integer
    Public punto1 As Integer
    Public punto2 As Integer
    Public P1 As Integer
    Public P2 As Integer
    Public punto3 As Integer
    Public setparam As Integer
    Public param As String
    Public id_concessionario As Integer
    Public win As String
    Public giorno As String
    Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
        bindata()
        ''  Me.TxtDataChiamata.Text = ViewState("giorno")
        If Not Request.Params("TxtCodiceConces") = "" Then
            Me.TxtCodiceConces.Text = Request.Params("TxtCodiceConces")
            Label3.Visible = False
            Me.TxtRagSociCoConc.Text = Request.Params("TxtRagSociCoConc")
        End If
 
        If TxtDataChiamata.Text = "" Then
            TxtDataChiamata.Text = Date.Now
            Data = TxtDataChiamata.Text
            Format(Data, "yyyy/dd/mm HH:mm:ss").Replace(":", ".")
        End If
        Page.Title = "Gestione Inserimento Chiamate Concessionario"
        lblRicerca.Visible = False
        If Not IsPostBack Then
            BidCheckBox()
        End If
        BtnRicerca.Visible = True
        If Not IsPostBack Then
            param = Request.QueryString("loginInfo")
            If param = 2 Then
                ViewState("param") = "2"
                id_concessionario =
Request.QueryString("id_concessionario")
                lblRicerca.Visible = False
                lbl_idconcessionario.Visible = False
                caricaCampi()
                SettacheckBox()
            End If
        End If
    End Sub
    Private Sub bindata()
        Dim i As Integer
        Dim DataInizio As String
        Dim DataFine As String
        If (txtStartDate.Text <> "" And txtEndDate.Text = "") Then
            txtEndDate.Text = txtStartDate.Text
        End If
        If (txtStartDate.Text = "" And txtEndDate.Text <> "") Then
        txtStartDate.Text = txtEndDate.Text
        End If
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As OleDbDataAdapter
        'If (txtStartDate.Text = "") And (txtEndDate.Text = "") And
(TxtCodiceConces2.Text = "") Then
        '    lblRicerca.Visible = True
        '    lblRicerca.Text = "Inserire un Parametro per la ricerca"
        '    Exit Sub
        'End If
        If txtStartDate.Text <> "" And txtEndDate.Text <> "" Then
            DataInizio = txtStartDate.Text
            DataFine = txtEndDate.Text
            Format(DataInizio, "dd/MM/yyyy")
            Format(DataFine, "dd/MM/yyyy")
        End If
        Dim TxtCodiceConces As String = Request.QueryString("loginInfoId")
        objCon.Open()
        ''   cod_concessionario like '%" &
Me.TxtCodiceConces.Text.Replace("'", "''") & "%'"
        '
        If (txtStartDate.Text <> "" And txtEndDate.Text <> "" And
TxtCodiceConces2.Text <> "") Then
            sql2 = New OleDbDataAdapter("select
Numerofattura,RagioneSociale,cognomechiamante,CodiceConcessionario,data_chiamata,ora_chiamata,id_concessionario
from Tbt_Concessionario where CodiceConcessionario=('" &
DoQuotes((TxtCodiceConces2.Text)) & "') and Data_Chiamata >=('" &
DateToNumber(DataInizio) & "') and Data_Chiamata <= ('" &
DateToNumber(DataFine) & "') order by Data_Chiamata desc", objCon)
        ElseIf (txtStartDate.Text <> "" And txtEndDate.Text <> "" And
TxtCodiceConces2.Text = "") Then
            sql2 = New OleDbDataAdapter("select
Numerofattura,RagioneSociale,cognomechiamante,CodiceConcessionario,data_chiamata,ora_chiamata,id_concessionario
from Tbt_Concessionario where  Data_Chiamata >=('" &
DateToNumber(DataInizio) & "') and Data_Chiamata <= ('" &
DateToNumber(DataFine) & "')order by Data_Chiamata desc", objCon)
        ElseIf (txtStartDate.Text = "" And txtEndDate.Text = "" And
TxtCodiceConces2.Text <> "") Then
            sql2 = New OleDbDataAdapter("select
Numerofattura,RagioneSociale,cognomechiamante,CodiceConcessionario,data_chiamata,ora_chiamata,id_concessionario
from Tbt_Concessionario where CodiceConcessionario=(" &
DoQuotes(TxtCodiceConces2.Text) & ") order by Data_Chiamata desc", objCon)
        ElseIf (txtStartDate.Text = "" And txtEndDate.Text = "" And
TxtCodiceConces2.Text = "") Then
            sql2 = New OleDbDataAdapter("select
Numerofattura,RagioneSociale,cognomechiamante,CodiceConcessionario,data_chiamata,ora_chiamata,id_concessionario
from Tbt_Concessionario  order by Data_Chiamata desc ", objCon)
        Else
        End If
        Dim querydataset As DataSet = New DataSet()
        Dim a As String
        sql2.Fill(querydataset)
        If querydataset.Tables(0).Rows.Count > 0 Then
            For i = 0 To querydataset.Tables(0).Rows.Count - 1
                querydataset.Tables(0).Rows(i).Item("ora_chiamata") =
NumberToTime(querydataset.Tables(0).Rows(i).Item("ora_chiamata").ToString)
                querydataset.Tables(0).Rows(i).Item("data_chiamata") =
NumberToDate(querydataset.Tables(0).Rows(i).Item("data_chiamata").ToString)
            Next i
            lblRicerca.Text = ""
            GridView2.Visible = True
            GridView2.DataSource = querydataset
            GridView2.DataBind()
        Else
            lblRicerca.Visible = True
            lblRicerca.Text = "Nessuna corrispondenza trovata"
            GridView2.Visible = False
        End If
    End Sub
    Protected Sub GridView2_PageIndexChanging(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView2.PageIndexChanging
        GridView2.PageIndex = e.NewPageIndex
        bindata()
    End Sub
    Protected Sub BtnSalva_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnSalva.Click
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As OleDbDataAdapter
        ''Dim giorno As String
        Dim ora As String
        giorno = Me.TxtDataChiamata.Text
        ViewState("giorno") = giorno
        ''Date.Now.ToString("dd/MM/yyyy")
        ora = Date.Now.ToString("HH:mm:ss")
        Dim codiceconcess As String
        Dim codiceconcess2 As String
        codiceconcess2 = TxtRagSociCoConc.Text
        codiceconcess = TxtCodiceConces.Text
        lbl_idconcessionario.Visible = False
        objCon.Open()
        Dim trans As OleDbTransaction
        trans = objCon.BeginTransaction
        ValidazioneCampi()
        lbl_idconcessionario.Visible = False
        If setparam = 1 Then
            If (BtnSalva.Text = "Modifica") Then
                win = "2"
                If (win <> ViewState("param")) Then
                    SetIdConcessionario()
                End If
                lbl_idconcessionario.Text =
ViewState("lbl_idconcessionario.Text")
                BtnSalva.Text = "Salva"
                setwrite()
                Label3.Visible = False
                Exit Sub
            End If
            If (BtnSalva.Text = "Salva") And lbl_idconcessionario.Text <>
"" Then
                Label3.Visible = False
                modifica()
                BtnSalva.Text = "Modifica"
                SetReadonly()
                BtnRicerca.Visible = True
                bind()
                lbl_idconcessionario.Text = ""
                Exit Sub
            End If
            If (BtnSalva.Text = "Salva") And lbl_idconcessionario.Text =
"" Then
                Label3.Visible = False
                lbl_idconcessionario.Text = ""
                Try
                    Dim sql1 As String = String.Empty
                    sql1 = "INSERT INTO Tbt_Concessionario "
                    sql1 &= "(DescTelefono1"
                    sql1 &= ",DescTelefono2"
                    sql1 &= ",CognomeChiamante"
                    sql1 &= ",RagioneSociale"
                    sql1 &= ",Relazione"
                    sql1 &= ",CodiceConcessionario"
                    sql1 &= ",NumeroFattura"
                    sql1 &= ",data_chiamata"
                    sql1 &= ",ora_chiamata"
                    sql1 &= ",Nota_descrittiva"
                    sql1 &= ")values"
                    sql1 &= "('" & DoQuotes(TxtTelefono1.Text) & "'"
                    sql1 &= ",'" & DoQuotes(TxtTelefono2.Text) & "'"
                    sql1 &= ",'" & DoQuotes(TxtCoDelchiama.Text) & "'"
                    sql1 &= ",'" & DoQuotes(TxtRagSociCoConc.Text) & "'"
                    sql1 &= ",'" & DoQuotes(TxtRelChiamante.Text) & "'"
                    sql1 &= ",'" & DoQuotes(TxtCodiceConces.Text) & "'"
                    sql1 &= ",'" & DoQuotes(TxtNumFattura.Text) & "'"
                    sql1 &= ",'" & DateToNumber(giorno) & "'"
                    sql1 &= ",'" & TimeToNumber(ora) & "'"
                    sql1 &= ",'" & DoQuotes(TxtNotaDescrittiva.Text) & "'"
                    sql1 &= ")"
                    Dim comm As OleDbCommand = New OleDbCommand
                    comm.Connection = objCon
                    'Inizia la transazione
                    comm.Transaction = trans
                    'prima query
                    comm.CommandText = sql1
                    comm.ExecuteNonQuery()
                    'eseguo la transazione
                    trans.Commit()
                Catch ex As SqlException
                    'se si sono verificati errori faccio il rollback
                    trans.Rollback()
                    Response.Write(ex.ToString())
                Finally
                    objCon.Close()
                End Try
                BtnSalva.Text = "Modifica"
                SetReadonly()
                BtnRicerca.Visible = True
                bind()
                Me.TxtDataChiamata.Text = ViewState("giorno")
            Else
            End If
        Else
            Label3.Visible = True
            Label3.Text = "****"
            lblRicerca.Text = "***"
        End If
    End Sub
    Private Sub ValidazioneCampi()
        setparam = 1
        If TxtCodiceConces.Text = "" Then
            punto3 = 0
            Label3.Text = "****"
            setparam = 0
        Else
            punto3 = 1
        End If
    End Sub
    Sub controllacampi(ByVal TestBox As TextBox, ByVal a As Integer)
        If a = 1 Then
            If IsNumeric(TestBox) Then
                a = "Errore dati nella Casella" + Convert.ToString(TestBox)
                lblRicerca.Text = "Errore dati nella Casella" + a
            End If
        End If
    End Sub
    Private Sub modifica()
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As OleDbDataAdapter
        Dim mm As DateTime
        mm = Date.Now
        objCon.Open()
        Dim trans As OleDbTransaction
        trans = objCon.BeginTransaction()
        Try
            Label3.Visible = False
            DeleteId_concessionario()
            Dim sql1 As String = "UPDATE Tbt_Concessionario SET
DescTelefono1= '" & DoQuotes(TxtTelefono1.Text) & " ' ,DescTelefono2= '" &
DoQuotes(TxtTelefono2.Text) & " ',CognomeChiamante='" &
DoQuotes(TxtCoDelchiama.Text) & "',RagioneSociale='" &
DoQuotes(TxtRagSociCoConc.Text) & "',Relazione='" &
DoQuotes(TxtRelChiamante.Text) & "',CodiceConcessionario=" &
DoQuotes(TxtCodiceConces.Text) & ",NumeroFattura='" &
DoQuotes(TxtNumFattura.Text) & "',Nota_descrittiva='" &
DoQuotes(TxtNotaDescrittiva.Text) & "'  where id_concessionario=(" &
(lbl_idconcessionario.Text) & ")"
            Dim comm As OleDbCommand = New OleDbCommand
            comm.Connection = objCon
            'Inizia la transazione
            comm.Transaction = trans
            'prima query
            comm.CommandText = sql1
            comm.ExecuteNonQuery()
            'eseguo la transazione
            trans.Commit()
        Catch ex As SqlException
            trans.Rollback()
            Response.Write(ex.ToString())
        Finally
            objCon.Close()
            setwrite()
        End Try
        Me.TxtDataChiamata.Text = ViewState("giorno")
        BtnSalva.Text = "Salva"
    End Sub
    Public Function Apici(ByVal s As String) As String
        Apici = Chr(34) & s & Chr(34)
    End Function
    Private Sub DeleteId_concessionario()
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As String
        Dim mm As DateTime
        mm = Date.Now
        objCon.Open()
        Dim trans As OleDbTransaction
        trans = objCon.BeginTransaction()
        win = "2"
        If (win <> ViewState("param")) Then
            SetIdConcessionario()
        End If
        Try
            sql2 = "delete from Tbt_MotivoChiamata where
id_concessionario= " & lbl_idconcessionario.Text & ""
            Dim comm As OleDbCommand = New OleDbCommand
            comm.Connection = objCon
            'Inizia la transazione
            comm.Transaction = trans
            'prima query
            comm.CommandText = sql2
            comm.ExecuteNonQuery()
            'eseguo la transazione
            trans.Commit()
        Catch ex As SqlException
            'se si sono verificati errori faccio il rollback
            trans.Rollback()
            Response.Write(ex.ToString())
        Finally
            'chiudiamo sempre le connessioni!
            objCon.Close()
        End Try
    End Sub
    Private Sub SetIdConcessionario()
        Dim id_concessionario As String
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As OleDbDataAdapter
        objCon.Open()
        sql2 = New OleDbDataAdapter("SELECT Max(id_concessionario)  AS
id_motivo from Tbt_Concessionario", objCon)
        Dim querydataset As DataSet = New DataSet()
        sql2.Fill(querydataset)
        If querydataset.Tables(0).Rows.Count > 0 Then
            id_concessionario =
querydataset.Tables(0).Rows(0).Item(0).ToString()
            ViewState("lbl_idconcessionario.Text") = id_concessionario
        Else
            lblRicerca.Visible = True
            lblRicerca.Text = "Nessuna corrispondenza trovata"
            '    GridView1.Visible = False
        End If
    End Sub
    Private Sub InsertcheckBox(ByVal id_motivo As Integer, ByVal
CodiceConcessionario As Integer)
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As String
        Dim mm As DateTime
        mm = Date.Now
        '' mm.Replace(".", ":")
        objCon.Open()
        Dim trans As OleDbTransaction
        trans = objCon.BeginTransaction()
        Try
            sql2 = "INSERT INTO Tbt_MotivoChiamata (id_motivo,
id_concessionario)values('" & id_motivo & "'," & lbl_idconcessionario.Text
& ")"
            Dim comm As OleDbCommand = New OleDbCommand
            comm.Connection = objCon
            'Inizia la transazione
            comm.Transaction = trans
            'prima query
            comm.CommandText = sql2
            comm.ExecuteNonQuery()
            'eseguo la transazione
            trans.Commit()
        Catch ex As SqlException
            'se si sono verificati errori faccio il rollback
            trans.Rollback()
            Response.Write(ex.ToString())
        Finally
            objCon.Close()
        End Try
    End Sub
    Protected Sub BtnModifica_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnRicerca.Click
        Response.Redirect("GestConcRicerca.aspx")
    End Sub
    Protected Sub TxtRelChiamante_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TxtRelChiamante.TextChanged
    End Sub
    Protected Sub TextBox9_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TxtNotaDescrittiva.TextChanged
    End Sub
    Protected Sub TxtNumFattura_TextChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles TxtNumFattura.TextChanged
    End Sub
    Private Sub caricaCampi()
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As OleDbDataAdapter
        objCon.Open()
        sql2 = New OleDbDataAdapter("select desctelefono1,desctelefono2, 
CognomeChiamante,RagioneSociale,Relazione,CodiceConcessionario,NumeroFattura,data_chiamata,ora_chiamata,Nota_descrittiva,id_concessionario
from Tbt_Concessionario where id_concessionario=(" & id_concessionario &
")", objCon)
        Dim querydataset As DataSet = New DataSet()
        sql2.Fill(querydataset)
        If querydataset.Tables(0).Rows.Count > 0 Then
            TxtTelefono1.Text =
querydataset.Tables(0).Rows(0).Item("desctelefono1").ToString()
            TxtTelefono2.Text =
querydataset.Tables(0).Rows(0).Item("desctelefono2").ToString()
            TxtCoDelchiama.Text =
querydataset.Tables(0).Rows(0).Item("CognomeChiamante").ToString()
            TxtRagSociCoConc.Text =
querydataset.Tables(0).Rows(0).Item("RagioneSociale").ToString()
            TxtRelChiamante.Text =
querydataset.Tables(0).Rows(0).Item("Relazione").ToString()
            TxtCodiceConces.Text =
querydataset.Tables(0).Rows(0).Item("CodiceConcessionario").ToString()
            TxtNumFattura.Text =
querydataset.Tables(0).Rows(0).Item("NumeroFattura").ToString()
            TxtDataChiamata.Text =
NumberToDate(querydataset.Tables(0).Rows(0).Item("data_chiamata").ToString())
+ " " +
NumberToTime(querydataset.Tables(0).Rows(0).Item("ora_chiamata").ToString())
            TxtNotaDescrittiva.Text =
querydataset.Tables(0).Rows(0).Item("Nota_descrittiva").ToString()
            lbl_idconcessionario.Text =
querydataset.Tables(0).Rows(0).Item("id_concessionario").ToString()
            ViewState("lbl_idconcessionario.Text") =
lbl_idconcessionario.Text
            ViewState("giorno") = TxtDataChiamata.Text
            SetReadonly()
            BtnSalva.Text = "Modifica"
        Else
            lblRicerca.Text = "Nessuna corrispondenza trovata"
        End If
    End Sub
    Private Sub PulisciMaschera()
        Dim i As Integer
        For i = 0 To CheckBoxList1.Items.Count - 1
            CheckBoxList1.Items.Item(i).Selected = False
            CheckBoxList1.Items.Item(i).Enabled = False
        Next
        TxtCoDelchiama.Text = ""
        TxtCodiceConces.Text = ""
        TxtDataChiamata.Text = ""
        TxtNotaDescrittiva.Text = ""
        TxtNumFattura.Text = ""
        TxtTelefono1.Text = ""
        TxtTelefono2.Text = ""
        TxtRelChiamante.Text = ""
        TxtRagSociCoConc.Text = ""
    End Sub
    Private Sub riempiListacheck()
    End Sub
    Private Sub setwrite()
        Dim i As Integer
        For i = 0 To CheckBoxList1.Items.Count - 1
            CheckBoxList1.Items.Item(i).Enabled = True
        Next
        TxtCoDelchiama.ReadOnly = False
        TxtNotaDescrittiva.ReadOnly = False
        TxtNumFattura.ReadOnly = False
        TxtTelefono1.ReadOnly = False
        TxtTelefono2.ReadOnly = False
        TxtRelChiamante.ReadOnly = False
        Me.TxtDataChiamata.Text = ViewState("giorno")
    End Sub
    Private Sub ControlliCampi()
    End Sub
    Private Sub SetReadonly()
        Dim i As Integer
        For i = 0 To CheckBoxList1.Items.Count - 1
            CheckBoxList1.Items.Item(i).Enabled = False
        Next
        TxtCoDelchiama.ReadOnly = True
        TxtDataChiamata.ReadOnly = True
        TxtNotaDescrittiva.ReadOnly = True
        TxtNumFattura.ReadOnly = True
        TxtTelefono1.ReadOnly = True
        TxtTelefono2.ReadOnly = True
        TxtRelChiamante.ReadOnly = True
        Me.TxtDataChiamata.Text = ViewState("giorno")
    End Sub
    Private Sub SettacheckBox()
        Dim i As Integer
        Dim conta As Integer
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As OleDbDataAdapter
        objCon.Open()
        sql2 = New OleDbDataAdapter("select id_motivo from
Tbt_MotivoChiamata where id_concessionario=(" &
(lbl_idconcessionario.Text) & ")", objCon)
        Dim querydataset As DataSet = New DataSet()
        sql2.Fill(querydataset)
        If querydataset.Tables(0).Rows.Count > 0 Then
            conta = querydataset.Tables(0).Rows.Count
            Dim j As Integer = 0
            For i = 0 To CheckBoxList1.Items.Count - 1
                If conta > 0 Then
                    If CheckBoxList1.Items.Item(i).Value =
querydataset.Tables(0).Rows(j).Item(0).ToString() Then
                        CheckBoxList1.Items.Item(i).Selected = True
                        j = j + 1
                        conta = conta - 1
                    End If
                End If
            Next
            lbl_idconcessionario.Text = ""
        Else
            lblRicerca.Visible = True
        End If
    End Sub
    Private Sub BidCheckBox()
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As OleDbDataAdapter
        objCon.Open()
        sql2 = New OleDbDataAdapter("select id_motivo,Descrizione from
Tbt_IdentificativoChiamata", objCon)
        Dim querydataset As DataSet = New DataSet()
        sql2.Fill(querydataset)
        If querydataset.Tables(0).Rows.Count > 0 Then
            CheckBoxList1.DataSource = querydataset
            CheckBoxList1.DataValueField = "id_motivo"
            CheckBoxList1.DataTextField = "Descrizione"
            CheckBoxList1.DataBind()
        Else
            lblRicerca.Visible = True
        End If
    End Sub
    Private Sub bind()
        Dim i As Integer
        Dim cod As Integer
        win = "2"
        If (win <> ViewState("param")) Then
            SetIdConcessionario()
        End If
        lbl_idconcessionario.Text = ViewState("lbl_idconcessionario.Text")
        For i = 0 To CheckBoxList1.Items.Count - 1
            If CheckBoxList1.Items.Item(i).Selected = True Then
                cod = CheckBoxList1.Items.Item(i).Value
                InsertcheckBox(cod, lbl_idconcessionario.Text)
            End If
        Next
    End Sub
    Protected Sub BtnLettura_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnPulisci.Click
        ViewState("param") = ""
        lbl_idconcessionario.Visible = False
        PulisciMaschera()
        lbl_idconcessionario.Text = ""
        setwrite()
        BtnRicerca.Visible = True
        BtnSalva.Text = "Salva"
        'If TxtDataChiamata.Text = "" Then
        '    TxtDataChiamata.Text = Date.Now
        'End If
    End Sub
    Protected Sub TxtCodiceConces_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TxtCodiceConces.TextChanged
        Label3.Text = ""
    End Sub
    Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
CheckBoxList1.SelectedIndexChanged
    End Sub
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles GridView2.SelectedIndexChanged
    End Sub
    Protected Sub BtnRicerca0_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnRicerca0.Click
        bindata()
    End Sub
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView2.RowCommand
        GridView2.Visible = True
        If e.CommandName = "Select" Then
            Dim intRiga As Integer = e.CommandArgument
            id_concessionario = Me.GridView2.DataKeys(intRiga).Value
            caricaCampi()
        End If
        If e.CommandName = "Page" Then
            bindata()
        End If
    End Sub
    Protected Sub BtnPulisci0_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnPulisci0.Click
        TxtCodiceConces2.Text = ""
        txtStartDate.Text = ""
        txtEndDate.Text = ""
        GridView2.Columns.Clear()
        GridView2.Visible = False
    End Sub
    Protected Sub BtnSetta_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnSetta.Click
        Response.Redirect("GestCheck.aspx")
    End Sub
    Protected Sub TxtDataChiamata_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TxtDataChiamata.TextChanged
    End Sub
End Class
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Diagnostics
Imports System.Configuration
Imports Utility
Partial Class GestCheck
    Inherits 
System.Web.UI.Page
    Public idconcess As String
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
        Page.Title = "Gestione check box"
        EseguiRicerca()
    End Sub
    Private Sub EseguiRicerca()
        Dim objCon As OleDbConnection
        Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
        objCon = New OleDbConnection(connectionstring)
        Dim sql2 As OleDbDataAdapter
        Dim sSQL As String = String.Empty
        Dim sWHERE As String = String.Empty
        Dim TxtCodiceConces As String = Request.QueryString("loginInfoId")
        sSQL = "select id_motivo as idmotivo ,descrizione as
CodiceConcessionario from Tbt_IdentificativoChiamata  order by id_motivo"
 
        objCon.Open()
        sql2 = New OleDbDataAdapter(sSQL & sWHERE, objCon)
        Dim querydataset As DataSet = New DataSet()
        sql2.Fill(querydataset)
        If querydataset.Tables(0).Rows.Count > 0 Then
            GridView1.DataSource = querydataset
            GridView1.DataBind()
        Else
            lblRicerca.Visible = True
            lblRicerca.Text = "Nessuna corrispondenza trovata"
            GridView1.Visible = False
        End If
    End Sub
    Protected Sub cmdRicerca_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdElimina.Click
        EseguiRicerca()
    End Sub
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
        Dim oCmd As HtmlInputButton
        Dim oRiga As DataRowView
        Dim sCodice As String = String.Empty
        Dim sDescrizione As String = String.Empty
        oCmd = CType(e.Row.FindControl("cmdSelect"), HtmlInputButton)
        oRiga = CType(e.Row.DataItem, DataRowView)
        If Not oRiga Is Nothing Then
            sCodice = oRiga.Row("codiceconcessionario").ToString
            ''sDescrizione = oRiga.Row("CognomeChiamante").ToString
        End If
        If Not oCmd Is Nothing Then
            oCmd.Attributes.Add("onclick", "javascript:assegnaRiga('" &
sCodice & "','" & sDescrizione & "');")
        End If
    End Sub
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
    End Sub
    Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles
GridView1.SelectedIndexChanging
        GridView1.PageIndex = e.NewSelectedIndex
        EseguiRicerca()
    End Sub
    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        EseguiRicerca()
    End Sub
    Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles
GridView1.RowDeleted
    End Sub
    Protected Sub BtnAnnulla_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdElimina.Click
    End Sub
    Protected Sub cmdRicerca0_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdElimina.Click
        lbl_idconcessionario.Text = ""
        Dim objCon As OleDbConnection
        If txtRagioneSociale.Text <> "" Then
            Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
            objCon = New OleDbConnection(connectionstring)
            Dim sql2 As String
            Dim mm As DateTime
            mm = Date.Now
            objCon.Open()
            Dim trans As OleDbTransaction
            trans = objCon.BeginTransaction
            Try
                sql2 = "delete from Tbt_IdentificativoChiamata where
id_motivo= " & ViewState("idconcess") & ""
                Dim comm As OleDbCommand = New OleDbCommand
                comm.Connection = objCon
                'Inizia la transazione
                comm.Transaction = trans
                'prima query
                comm.CommandText = sql2
                comm.ExecuteNonQuery()
                'eseguo la transazione
                trans.Commit()
            Catch ex As SqlException
                'se si sono verificati errori faccio il rollback
                trans.Rollback()
                Response.Write(ex.ToString())
            Finally
                'chiudiamo sempre le connessioni!
                objCon.Close()
            End Try
            EseguiRicerca()
            txtRagioneSociale.Text = ""
        Else
            lbl_idconcessionario.Text = "Eseguire una selezione"
        End If
    End Sub
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand
        GridView1.Visible = True
        If e.CommandName = "Select" Then
            Dim intRiga As Integer = e.CommandArgument
            ViewState("idconcess") = Me.GridView1.DataKeys(intRiga).Value
            ''   ViewState("idconcess") =
GridView1.Rows(intRiga).Cells(1).Text
            txtRagioneSociale.Text =
Me.GridView1.Rows(intRiga).Cells(1).Text
 
        End If
        If e.CommandName = "Page" Then
        End If
    End Sub
    Private Sub insertConcess()
    End Sub
    Private Sub modifica()
 
    End Sub
    Private Sub DeleteId_concessionario()
 
    End Sub
    Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdUpdate.Click
        lbl_idconcessionario.Text = ""
        Dim objCon As OleDbConnection
        If txtRagioneSociale.Text <> "" Then
            Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
            objCon = New OleDbConnection(connectionstring)
            Dim mm As DateTime
            mm = Date.Now
            Dim sql1
            objCon.Open()
            Dim trans As OleDbTransaction
            trans = objCon.BeginTransaction()
            Try
                DeleteId_concessionario()
                sql1 = "UPDATE Tbt_IdentificativoChiamata SET Descrizione=
'" & DoQuotes(txtRagioneSociale.Text) & " ' where id_motivo =" &
(ViewState("idconcess")) & ""
                Dim comm As OleDbCommand = New OleDbCommand
                comm.Connection = objCon
                'Inizia la transazione
                comm.Transaction = trans
                'prima query
                comm.CommandText = sql1
                comm.ExecuteNonQuery()
                'eseguo la transazione
                trans.Commit()
            Catch ex As SqlException
                trans.Rollback()
                Response.Write(ex.ToString())
            Finally
                objCon.Close()
            End Try
            EseguiRicerca()
        Else
            lbl_idconcessionario.Text = "Eseguire una selezione"
        End If
    End Sub
    Protected Sub cmdInsert_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdInsert.Click
        lbl_idconcessionario.Text = ""
        If txtRagioneSociale.Text <> "" Then
            Dim objCon As OleDbConnection
            Dim connectionstring As String =
System.Configuration.ConfigurationManager.ConnectionStrings("strCon").ConnectionString
            objCon = New OleDbConnection(connectionstring)
            Dim sql2 As String
            Dim mm As DateTime
            mm = Date.Now
            '' mm.Replace(".", ":")
            objCon.Open()
            Dim trans As OleDbTransaction
            trans = objCon.BeginTransaction()
            Try
                sql2 = "INSERT INTO Tbt_IdentificativoChiamata (
Descrizione)values('" & txtRagioneSociale.Text & "')"
                Dim comm As OleDbCommand = New OleDbCommand
                comm.Connection = objCon
                'Inizia la transazione
                comm.Transaction = trans
                'prima query
                comm.CommandText = sql2
                comm.ExecuteNonQuery()
                'eseguo la transazione
                trans.Commit()
            Catch ex As SqlException
                'se si sono verificati errori faccio il rollback
                trans.Rollback()
                Response.Write(ex.ToString())
            Finally
                objCon.Close()
            End Try
            EseguiRicerca()
        Else
            lbl_idconcessionario.Text = "Inserire una descrizione"
        End If
    End Sub
    Protected Sub BtnAnnulla_Click1(ByVal sender As Object, ByVal e As
System.EventArgs) Handles BtnAnnulla.Click
        Response.Redirect("Default.aspx")
    End Sub
End Class
-- 
questo articolo e` stato inviato via web dal servizio gratuito 
http://www.newsland.it/news
 segnala gli abusi ad 
ab...@newsland.it

Tom22 ha scritto:
