PDA

View Full Version : [ASP.Net(VB] Scrivere in un db


<Gabrik>
08-10-2006, 11:40
Allora come da titolo come faccio a scrivere in un db su SqlServer?
che modifiche devo apportare a questo sorgente per fare in modo che scriva nel db?
Dim Utente As String
Dim PassUtente As String

Dim IDUtente As Integer ' variebile del db
Dim Nomedb As String 'variabile del db
Dim Passworddb As String 'variabile del db

Dim StringaSQL = "Driver={Sql Server};Server=.\SQLEXPRESS;Database=nodb;Uid=sa;Pwd=sqlpass"
Dim ConnessioneSQL As New System.Data.Odbc.OdbcConnection(StringaSQL)
Dim QuerySQL As String = "SELECT ID, Nome, Password , FROM Tab Where Nome = '" & TextBox1.Text & "' and Password = '" & TextBox2.Text & "' "
Dim Comando As New System.Data.Odbc.OdbcCommand(QuerySQL, ConnessioneSQL)
Dim Reco As System.Data.Odbc.OdbcDataReader
ConnessioneSQL.Open()
Reco = Comando.ExecuteReader
Utente = TextBox1.Text
PassUtente = TextBox2.Text
If Utente = "" Or PassUtente = "" Then
MsgBox("Inserire Nome Utente o Password", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Informazione")

Else

While (Reco.Read())
With (Reco)
IDUtente = !ID
Nomedb = !Nome
Passworddb = !Password

Label3.Text = Nomedb
Label4.Text = Passworddb
End With


End While
ConnessioneSQL.Close()
Reco.Close()

If Utente = Label3.Text And PassUtente = Label4.Text Then
Session("idditta") = IDDit
Response.Redirect("~/Default.aspx?id=" & Session.SessionID)
Utente = TextBox1.Text
PassUtente = TextBox2.Text

Else
MsgBox("Password Errata!", MsgBoxStyle.Critical +MsgBoxStyle.OkOnly, "Gestione Errori")
Utente = ""
PassUtente = ""
End If
End If

<Gabrik>
08-10-2006, 17:23
up

mattia.pascal
08-10-2006, 17:46
Una delle soluzioni è utilizzare l'SQL e fare un INSERT