Ja tak. men hvordan?
Jeg har fundet følgende på nettet, men det compilerer ikke:
protected int myID
{
get
{
object o=Request.QueryString["ID"];
if (o==null)
throw new
ApplicationException("ID is required to be passed");
else
try
{
return Convert.ToInt32(o,10);
}
catch(Exception err)
{
throw new ApplicationException("Invalid ID", err);
}
}
}
----------------------
Og her en gang til min aspx og aspx.cs filer. Måske hjælper det at finde ud af hvilke ændring skulle laves i min kode:
aspx:
--
%@ Page language="c#" Codebehind="Detaljer3.aspx.cs" AutoEventWireup="false" Inherits="EIS.Detaljer3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Details3</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="
http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="Style.css" type="text/css" rel="stylesheet">
<SCRIPT language="JavaScript">
function Print()
{
window.print();
}
</SCRIPT>
</HEAD>
<body bgColor="#6a828b">
<form id="Form1" method="post" runat="server">
<P>
<TABLE id="Table2" borderColor="#000000" cellSpacing="0" cellPadding="1" width="720" align="center" bgColor="#eeffff" border="1"><TR><TD>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="718" align="center" bgColor="#eeffff" border="0"><TR>
<TD width="18"></TD>
<TD width="190"></TD>
<TD width="20"></TD>
<TD align="left" width="490"></TD>
</TR>
<TR>
<TD width="18" height="30"></TD>
<TD width="190" height="30"></TD>
<TD width="20" height="30"></TD>
<TD align="left" width="490" height="30"></TD>
</TR>
<TR>
<TD width="18"></TD>
<TD width="190">ID:</TD>
<TD width="20"></TD>
<TD width="490"><asp:label id="lblID" runat="server" Width="200px"></asp:label></TD>
</TR>
<TR>
<TD style="HEIGHT: 16px" width="18"></TD>
<TD style="HEIGHT: 16px" width="190">Stoffets/produkts handelsnavn:</TD>
<TD style="HEIGHT: 16px" width="20"></TD>
<TD width="490"><asp:label id="lblNavn" runat="server"></asp:label></TD>
</TR>
<TR>
<TD width="18"></TD>
<TD width="190">E-mail:</TD>
<TD width="20"></TD>
<TD width="490"><asp:label id="lblEmail" runat="server"></asp:label></TD>
</TR><TR>
<TD width="18" height="30"></TD>
<TD width="700" colSpan="3" height="30">
<P align="center"><IMG height="1" src="images/graaprik.gif" width="700"></P>
</TD>
</TR>
<TR>
<TD width="18"></TD>
<TD width="190">Tlf:</TD>
<TD width="20"></TD>
<TD width="490"><asp:textbox id="fTlf" runat="server" Width="200px"></asp:textbox></TD>
</TR>
<TR>
<TD width="18"></TD>
<TD width="190">E-mail</TD>
<TD width="20"></TD>
<TD width="490"><asp:textbox id="fEmail" runat="server" Width="200px"></asp:textbox></TD>
</TR>
<TR><TD width="18"></TD>
<TD width="190">Anerkendt?</TD>
<TD width="20"></TD>
<TD width="490"><asp:checkbox id="fAnerkendt" runat="server" Text="Ja"></asp:checkbox></TD>
</TR>
<TR>
<TD width="18" height="30"></TD>
<TD width="190" height="30"></TD>
<TD width="20" height="30"></TD>
<TD width="490" height="30"></TD>
</TR><TR>
<TD width="18"></TD>
<TD width="190"></TD>
<TD width="20"></TD>
<TD width="490"><asp:button id="fbOpdater" runat="server" Width="80px" Text="Opdater"></asp:button>
<INPUT style="WIDTH: 80px; HEIGHT: 20px" onclick="Print();" type="button" value="Udskriv" name="knap"></TD>
</TR>
<TR>
<TD width="18"></TD>
<TD width="190"></TD>
<TD width="20"></TD>
<TD width="490"></TD>
</TR>
<TR>
<TD width="18" height="30"></TD>
<TD width="190" height="30"></TD>
<TD width="20" height="30"></TD>
<TD width="490" height="30"></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</P>
</form>
</body>
</HTML>
----
aspx.cs:
--
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.OleDb;
using System.IO;
namespace EIS
{
/// Summary description for Detaljer3.
public class Detaljer3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblID;
protected System.Web.UI.WebControls.Label lblNavn;
protected System.Web.UI.WebControls.Label lblEmail;
protected System.Web.UI.WebControls.CheckBox fAnerkendt;
protected System.Web.UI.WebControls.TextBox fTlf;
protected System.Web.UI.WebControls.TextBox fEmail;
protected System.Web.UI.WebControls.Button fbOpdater;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
InsertFilValues();
}
}
private void InsertFilValues()
{
using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + MapPath("fpdb/EIS.mdb")))
using (OleDbCommand command = new OleDbCommand("SELECT ID,Navn,Forhandler,File1,File2,File3,Begrundelse,Koebsdato,Fremstiller,DitNavn,Email,Tlf,Oenske_svar,Sagsbehandler,J_nr,Proevenr,Anerkendt FROM eis WHERE ID = @ID", connection))
{
command.Parameters.Add("@ID", typeof(int));
command.Parameters["@ID"].Value = int.Parse(Request.QueryString["ID"]);
command.Connection.Open();
using (OleDbDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
lblID.Text = reader.GetInt32(reader.GetOrdinal("ID")).ToString();
lblNavn.Text = reader["Navn"].ToString();
lblEmail.Text = reader["Email"].ToString();
fTlf.Text = reader["Tlf"].ToString();
fEmail.Text = reader["Email"].ToString();
if (reader["Anerkendt"].ToString().Equals("False"))
fAnerkendt.Checked = false;
else
fAnerkendt.Checked = true;
connection.Close();
}
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
InitializeComponent();
base.OnInit(e);
}
/// </summary>
private void InitializeComponent()
{
this.fbOpdater.Click += new System.EventHandler(this.fbOpdater_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void fbOpdater_Click(object sender, System.EventArgs e)
{
int id = int.Parse(lblID.Text);
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + MapPath("fpdb/EIS.mdb");
OleDbConnection conn = new OleDbConnection(strConn);
OleDbCommand command = new OleDbCommand("UPDATE eis SET Tlf=@tlf, Email=@email, Anerkendt=@anerkendt WHERE id=@id", conn);
OleDbParameter parameter = new OleDbParameter("@id", OleDbType.Integer);
parameter.Value = id;
command.Parameters.Add(parameter);
OleDbParameter parTlf = new OleDbParameter("tlf", OleDbType.VarChar);
parTlf.Value = fTlf.Text;
command.Parameters.Add(parTlf);
OleDbParameter parEmail = new OleDbParameter("Email", OleDbType.VarChar);
parEmail.Value = fEmail.Text;
command.Parameters.Add(parEmail);
OleDbParameter parAnerkendt = new OleDbParameter("@anerkendt", OleDbType.Boolean);
parAnerkendt.Value = fAnerkendt.Checked;
command.Parameters.Add(parAnerkendt);
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}
}
}
---
Mvh