Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Problema insert con vb e sql server

    Salve, ho un problema con l'inserimento all'intrno di un database sql server attraverso una mascgerina di vb, questo è il codice da me elaborato, ma nn succede niente qulcuno s a aiutarmi? grazie

    il Db risiede in locale e ha il nome di esame


    Imports System.Data.SqlClient
    Imports System.Data
    Public Class Giuseppe

    Private Sub selectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles selButton.Click

    unoCheckBox.Checked = True
    dueCheckBox.Checked = True
    treCheckBox.Checked = True
    End Sub

    Private Sub delButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delButton.Click
    unoCheckBox.Checked = False
    dueCheckBox.Checked = False
    treCheckBox.Checked = False
    End Sub


    Private connection As SqlConnection
    Protected Sub inviaButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles inviaButton.Click
    Dim command As New SqlCommand
    command.Connection() = connection
    Dim flag As String
    Dim flag1 As String
    Dim flag2 As String
    If unoCheckBox.Checked Then
    flag = "N"
    Else : flag = "S"
    End If
    If dueCheckBox.Checked Then
    flag1 = "N"
    Else : flag1 = "S"
    End If
    If treCheckBox.Checked Then
    flag2 = "N"
    Else : flag2 = "S"
    End If

    command.CommandText() = "INSERT INTO esame (Nome,Cognome,Esame1,Esame2,Esame3,Sostenuto1,Sost enuto2,Sostenuto3) values ('" + nomeTextBox.Text + "','" + TextBox1.Text + "','" + esame1TextBox.Text + "','" + esame2TextBox.Text + "','" + esame3TextBox.Text + "','" + flag + "','" + flag1 + "','" + flag2 + "')"

    MessageBox.Show("Registrazione effettuata con uccesso.")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Try
    connection = New SqlConnection
    Dim connectionString As String = "Data Source=ADMIN-09F708620\sqlexpress; Initial Catalog=esami;"
    connection.ConnectionString() = connectionString
    connection.Open()
    Catch
    MessageBox.Show(Err.Description)
    End Try End Sub
    End Class



    grazie
    www.ertinformatica.com Vendita computer e hardware

    www.risorsefantacalcio.it News, voti del Corriere e della Gazzetta, e tanto altro.

    www.parrocchie.eu Parrocchie e siti cattolici italiani

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    669
    se ho capito bene usi vb.net.

    e da quello che ho capito non di funziona perchè non lanci il comando

    Dim command As New SqlCommand
    command.Connection = connection
    command.CommandText = "INSERT INTO esame (Nome,Cognome,Esame1,Esame2,Esame3,Sostenuto1,Sost enuto2,Sostenuto3) values ('" + nomeTextBox.Text + "','" + TextBox1.Text + "','" + esame1TextBox.Text + "','" + esame2TextBox.Text + "','" + esame3TextBox.Text + "','" + flag + "','" + flag1 + "','" + flag2 + "')"

    cmd.ExecuteNonQuery()

    ciao

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 © 2025 vBulletin Solutions, Inc. All rights reserved.