<%@ page language="vb" autoeventwireup="false" %>
<%@ import namespace="mysql.data.mysqlclient" %>
<%@ import namespace="system.data" %>
<html>
<head>
</head>
<script runat="server">
private conn as mysqlconnection
sub page_init (sender as object, e as eventargs) handles me.init
if page.ispostback then
'response.write(" pagina in postback ")
end if
end sub
sub page_load(sender as object, e as eventargs) handles me.load
'response.write(" questa è la sub di load ")
end sub
sub page_prerender(sender as object, e as eventargs) handles me.prerender
'response.write(" Prerender ")
end sub
sub page_disposed(sender as object, e as eventargs) handles me.disposed
'response.write(" Disposed ")
end sub
sub gestione_button(sender as object, e as eventargs) handles button.click
'Response.Write(textbx.Text)
connetti_database()
crea_tabella() 'creo la tabella
If Not (controlla_tabella("giocatori")) Then
Response.Write(" La tabella giocatori NON esiste")
Else
Response.Write(" La tabella giocatori esiste")
End If
disconnetti_database()
end sub
sub connetti_database()
try
conn=new mysqlconnection("server=localhost; database=fantacalcio; user id=root; password=xxxxxxxx")
conn.Open()
Catch eccezione As Exception
Response.Write(eccezione.Message)
end try
end sub
sub disconnetti_database()
conn.close
end sub
Function controlla_tabella(ByVal nometabella As String) As Boolean
Try
Dim ds As DataSet
Dim dbda As MySqlDataAdapter = New MySqlDataAdapter
dbda.SelectCommand = New MySqlCommand("select * from " & nometabella, conn)
dbda.Fill(ds)
ds = Nothing
Return True
Catch eccezione As Exception
Return False
End Try
End Function
Sub crea_tabella() 'sub che se dio vuole mi crea la tabella e lo richiamo all'interno di gestione button
Try
Dim crt As MySqlDataAdapter = New MySqlDataAdapter
crt.SelectCommand = New MySqlCommand("CREATE TABLE giocatori(nome, char(40))", conn)
Response.Write("sono all'interno di creatabella ")
Catch eccezione As Exception
Response.Write(eccezione.Message)
End Try
End Sub
</script>
<form runat="server">
<asp:label runat="server" id="label1" text="Inserire nome giocatore: " />
<asp:textbox runat="server" id="textbx" textmode="singleline" />
<asp:button runat="server" id="button" text="Inserisci" />
</form>
<body>
</body>
</html>