Ciao
mi sto addentrando da poco con ASP.net e non riesco a capire come inserire un record in un db msyql.
Ho sempre utilizzato asp e qua sembra tutto differente
Il codice che sto usando è questo:
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%
Dim myConn as OdbcConnection
Dim tbServer = "xx.xx.xx.xx"
Dim tbDB = "xx"
Dim tbLogin = "xx"
Dim tbPwd = "xx"
myConn = New OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};SERVER="+tbServer+";PORT=3306;DATABASE="+t bDB+";USER="+tbLogin+";PASSWORD="+tbPwd+";OPTION=3 ;")
myConn.Open()
Response.Write("Connessione aperta con successo!")
' myConn.Close()
%>
<script language="VB" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim InsertCommand As SqlCommand = New SqlCommand()
InsertCommand.Connection = myConn
Dim sql As String
sql = "INSERT INTO pippo (oggetto) VALUES ('oggetto')"
InsertCommand.CommandText = sql
Try
'myConn.Open()
InsertCommand.ExecuteNonQuery()
Catch ex As Exception
response.Write(ex.ToString())
Finally
myConn.Close()
End Try
end sub
</script>
Come risultato mi da la classica pagina di errore di .net. Dimenitcavo, la connessione pare che vada a buon fine. Il provider è aruba sul quale ho altri lavori fatti con asp+mysql e che funzionano bene.
Cosa c'è da sapere? dove sto sbagliando?
Grazie a tutti

Rispondi quotando