Ordreform i C#.NET fejler..
er der en der kan se hvad der er galt her ? :using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Security;
namespace EbyteSolutions
{
/// <summary>
/// Summary description for Kundeoplysninger.
/// </summary>
public class Kundeoplysninger : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.UserControl ucShoppingCart;
protected System.Web.UI.WebControls.TextBox txtFornavn;
protected System.Web.UI.WebControls.TextBox txtEfternavn;
protected System.Web.UI.WebControls.TextBox txtAdresse;
protected System.Web.UI.WebControls.TextBox txtPostnummer;
protected System.Web.UI.WebControls.TextBox txtByen;
protected System.Web.UI.WebControls.TextBox txtEmail;
protected System.Web.UI.WebControls.TextBox txtBrugernavn;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.Button Confirm;
protected System.Data.SqlClient.SqlConnection connection;
protected System.Data.SqlClient.SqlDataAdapter db;
protected System.Data.SqlClient.SqlCommandBuilder cmdBuilder;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Confirm.Click += new System.EventHandler(this.Confirm_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Confirm_Click(object sender, System.EventArgs e)
{
if (IsValid)
{
SqlCommand cmd;
DataSet ordreDataSet = new DataSet();
connection = new SqlConnection();
connection.ConnectionString = "server=server;uid=user;pwd=pass;database=database";
string sql = "SELECT * FROM Kunder WHERE Fornavn='" + txtFornavn.Text +"' AND Efternavn=' " + txtEfternavn.Text + " ' AND Adresse=' " + txtAdresse.Text + " ' AND Postnummer=' " + txtPostnummer.Text + " ' AND Bynavn=' " + txtByen.Text + " ' AND Email=' " + txtEmail.Text + " ' AND Brugernavn=' " + txtBrugernavn.Text + " ' AND Password=' " + txtPassword.Text + " ' ";
SqlDataAdapter db = new SqlDataAdapter(sql, connection);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(db);
connection.Open();
db.Fill(ordreDataSet, "Kunder");
DataTable kunder = ordreDataSet.Tables["Kunder"];
DataRow kunde;
if (kunder.Rows.Count == 0)
{
kunde = kunder.NewRow();
kunde["Fornavn"] = txtFornavn.Text;
kunde["Efternavn"] = txtEfternavn.Text;
kunde["Adresse"] = txtAdresse.Text;
kunde["PostNummer"] = txtPostnummer.Text;
kunde["Bynavn"] = txtByen.Text;
kunde["Email"] = txtEmail.Text;
kunde["Brugernavn"] = txtEmail.Text;
kunde["Password"] = txtPassword.Text;
kunder.Rows.Add(kunde);
db.Update(ordreDataSet, "Kunder");
cmd = new SqlCommand("SELECT @@IDENTITY", connection);
kunde["KundeID"] = (Decimal) cmd.ExecuteScalar();
ordreDataSet.AcceptChanges();
}
else
kunde = kunder.Rows[0];
db.SelectCommand.CommandText = "SELECT * FROM Ordre WHERE 1=0";
cmdBuilder.RefreshSchema();
db.Fill(ordreDataSet, "Ordre");
DataTable ordre = ordreDataSet.Tables["Ordre"];
DataRow ordreRow = ordre.NewRow();
ordreRow["KundeID"] = kunde["KundeID"];
ordreRow["OrdreDato"] = DateTime.Now;
ordre.Rows.Add(ordreRow);
db.Update(ordreDataSet, "ordre");
cmd = new SqlCommand("SELECT @@IDENTITY", connection);
ordreRow["OrdreID"]= (Decimal) cmd.ExecuteScalar();
ordreDataSet.AcceptChanges();
db.SelectCommand.CommandText = "SELECT * FROM OrdreDetaljer WHERE 1=0";
cmdBuilder.RefreshSchema();
db.Fill(ordreDataSet, "OrdreDetaljer");
DataTable ordreDetaljer = ordreDataSet.Tables["OrdreDetaljer"];
DataTable shoppingCart = ((DataTable)Session["ShoppingCart"]);
foreach (DataRow row in shoppingCart.Rows)
{
DataRow ordreDetaljeRow = ordreDetaljer.NewRow();
ordreDetaljeRow["OrdreID"] = ordreRow["OrdreID"];
ordreDetaljeRow["VareID"] = row["VareID"];
ordreDetaljer.Rows.Add(ordreDetaljeRow);
}
db.Update(ordreDataSet, "OrdreDetaljer");
ordreDataSet.AcceptChanges();
Response.Redirect("confirm.aspx");
}
}
}
}