Created
May 23, 2014 09:41
-
-
Save s0ren/a1ab6991bd504959f184 to your computer and use it in GitHub Desktop.
Insæt i database efter "Sådan virker CRUD" - Create-delen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
// Vi skal bruge de her namespaces. Det står ikke i bogen! | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Configuration; | |
public partial class _Kontakt : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
} | |
protected void ButtonGem_Click(object sender, EventArgs e) | |
{ | |
SqlConnection conn = new SqlConnection(); | |
conn.ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ToString(); | |
SqlCommand cmd = new SqlCommand(); | |
cmd.Connection = conn; | |
cmd.CommandText = @"INSERT INTO Girlz | |
(Navn, Skonummer, Beskrivelse) VALUES (@Navn, @Skonummer, @Beskrivelse)"; | |
cmd.Parameters.AddWithValue("@Navn", TextBoxNavn.Text); | |
cmd.Parameters.AddWithValue("@Skonummer", TextBoxStr.Text); | |
cmd.Parameters.AddWithValue("@Beskrivelse", TextBoxBeskrivelse.Text); | |
conn.Open(); | |
cmd.ExecuteNonQuery(); | |
conn.Close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment