Skip to content

Instantly share code, notes, and snippets.

@s0ren
Created May 23, 2014 09:41
Show Gist options
  • Save s0ren/a1ab6991bd504959f184 to your computer and use it in GitHub Desktop.
Save s0ren/a1ab6991bd504959f184 to your computer and use it in GitHub Desktop.
Insæt i database efter "Sådan virker CRUD" - Create-delen
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