Imports System.Globalization Partial Class _Default Inherits System.Web.UI.Page Protected Sub btnDoInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDoInsert.Click Dim usrname As String usrname = User.Identity.Name Dim li As System.Web.UI.WebControls.ListItem li = radiolist.SelectedItem Dim selectedBanfor As String selectedBanfor = li.Text Dim selectedReason As String = String.Empty Dim IsSelectionsMade As Boolean = False For Each tmpListItem As ListItem In Reasons.Items If (tmpListItem.Selected) Then selectedReason += tmpListItem.Text + ", " IsSelectionsMade = True End If Next If (IsSelectionsMade) Then selectedReason = selectedReason.Substring(0, selectedReason.Length - 2) DoInsert(selectedBanfor, tbPlayerNickname.Text, tbIP.Text, selectedReason, tbDATE.Text, txtTime.Text, tbDetails.Text, usrname, False) Else End If End Sub Private Sub DoInsert(ByVal BanFor As String, ByVal PlayerNickName As String, ByVal IPAddress As String, ByVal Reasons As String, ByVal tbDATE As String, ByVal Time As String, ByVal Details As String, ByVal BannedBy As String, ByVal CaseClosed As Boolean) 'ConnectionString till databasen, ändra sökvägen så att den blir rätt Dim ConnectionString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" + Server.MapPath("~/App_Data/Database.mdf") + ";Integrated Security=True;User Instance=True" 'Skapa en ny SQL-connection med rätt ConnectionSring Dim CurrentSQLConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConnectionString) 'Skapa kommando-texten som sätter in en rad i tabellen Dim SQLCommand As String = "INSERT INTO Argobanlist (BanFor, PlayerNickName, IPAddress, Reasons, Date, Time , Details, BannedBy, CaseClosed) " SQLCommand += " VALUES ('" + BanFor + "', " SQLCommand += "'" + PlayerNickName + "', " SQLCommand += "'" + IPAddress + "', " SQLCommand += "'" + Reasons + "', " SQLCommand += "'" + tbDATE + "', " SQLCommand += "'" + Time + "', " SQLCommand += "'" + Details + "', " SQLCommand += "'" + BannedBy + "', " SQLCommand += "" + System.Convert.ToInt32(CaseClosed).ToString() + ")" 'Öppna anslutning till databasen CurrentSQLConnection.Open() 'Skapa nytt SQL-kommando Dim sqlCmd_InsertBan As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(SQLCommand, CurrentSQLConnection) 'Utför kommando sqlCmd_InsertBan.ExecuteNonQuery() Label9.Text = "Ban added" 'Stäng anslutningen till databasen igen CurrentSQLConnection.Close() End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If User.Identity.IsAuthenticated = False Then Server.Transfer("login.aspx") End If tbDATE.Text = Now.ToShortDateString.ToString If CheckBox2.Checked = False Then txtTime.Enabled = True End If If CheckBox2.Checked = True Then txtTime.Enabled = False Dim timenow As String timenow = Now.ToShortTimeString txtTime.Text = timenow End If ClientScript.RegisterStartupScript([GetType](), "show", "setTimeout('$find(\'bSelectDate\').show();',10);", True) End Sub End Class