Avatar billede fc-dong Nybegynder
03. februar 2008 - 15:34 Der er 3 kommentarer og
1 løsning

Hjælp mig med dette dato problem

Jeg har virkelig fået mig et problem med at oprette en dato i min access database, hvor den bytter om på DD-MD-ÅR
håber der er en venlig sjæl som kan jælpe mig med dette problem
Her er min kode:
---------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
  If condition = "" Then
    MM_IIf = ifFalse
  Else
    MM_IIf = ifTrue
  End If
End Function
%>
<%
If (CStr(Request("MM_insert")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_ConnOuresport1_STRING
    MM_editCmd.CommandText = "INSERT INTO vejret (vejrdato, vejrover, vejrtekst) VALUES (?, ?, ?)"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 135, 1, -1, MM_IIF(Request.Form("vejrdato"), Request.Form("vejrdato"), null)) ' adDBTimeStamp
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 203, 1, 536870910, Request.Form("vejrover")) ' adLongVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 203, 1, 536870910, Request.Form("vejrtekst")) ' adLongVarWChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    ' append the query string to the redirect URL
    Dim MM_editRedirectUrl
    MM_editRedirectUrl = "vejret_aendre.asp"
    If (Request.QueryString <> "") Then
      If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
        MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
      Else
        MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
      End If
    End If
    Response.Redirect(MM_editRedirectUrl)
  End If
End If
%>
<% Session.LCID = 1030 'Dutch regional setttings %>

<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="fejl.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
  If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
        (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>
<%
Dim RSvejret
Dim RSvejret_cmd
Dim RSvejret_numRows

Set RSvejret_cmd = Server.CreateObject ("ADODB.Command")
RSvejret_cmd.ActiveConnection = MM_ConnOuresport1_STRING
RSvejret_cmd.CommandText = "SELECT * FROM vejret"
RSvejret_cmd.Prepared = true

Set RSvejret = RSvejret_cmd.Execute
RSvejret_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/modul_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Ouresport</title>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--

/* BEGIN Advanced HTML Editor */
.dmx_btn    { width: 22px; height: 22px; border: 1px solid #ECE9D8; margin: 0; padding: 0; background-color: #ECE9D8; }
.dmx_btnOver { width: 22px; height: 22px; border: 1px outset; margin: 0; padding: 0; background-color: #FCF9E8; }
.dmx_btnDown { width: 22px; height: 22px; border: 1px inset; margin: 0; padding: 0; background-color: #FCF9E8; }
.dmx_btnNA  { width: 22px; height: 22px; border: 1px solid #ECE9D8; margin: 0; padding: 0; -moz-opacity:0.25; opacity:0.25; filter: alpha(opacity=25);}
.dmx_menuBar { background-color: #ECE9D8; }
/* END Advanced HTML Editor */
-->
</style>
<script language="javascript">
<!--
/* BEGIN Advanced HTML Editor */
var BaseURL = "../";
/* END Advanced HTML Editor */
//-->
</script>
<script language="JavaScript" src="../ScriptLibrary/AdvHTMLLang.js"></script>
<script language="JavaScript" src="../ScriptLibrary/AdvHTMLEdit.js"></script>
<!-- InstanceEndEditable -->
<link href="../style/ouresport.css" rel="stylesheet" type="text/css" />
</head>

<body><!-- DHTML Menu Builder Loader Code START -->
<div id="dmbri" style="position:absolute;">
<img src="menumodul/dmb_i.gif" name="dmbif" width="1" height="1" alt="" />
<img src="menumodul/dmb_m.gif" name="dmbjs" width="1" height="1" alt="" />
</div>
<script type="text/javascript">
var rimPath=null;var rjsPath=null;var rPath2Root=null;function InitRelCode(){var iImg;var jImg;var tObj;if(!document.layers){iImg=document.images['dmbif'];jImg=document.images['dmbjs'];tObj=jImg;}else{tObj=document.layers['dmbri'];if(tObj){iImg=tObj.document.images['dmbif'];jImg=tObj.document.images['dmbjs'];}}if(!tObj){window.setTimeout("InitRelCode()",700);return false;}rimPath=_gp(iImg.src);rjsPath=_gp(jImg.src);rPath2Root=rjsPath+"../";return true;}function _purl(u){return xrep(xrep(u,"%%REP%%",rPath2Root),"\\","/");}function _fip(img){if(img.src.indexOf("%%REL%%")!=-1) img.src=rimPath+img.src.split("%%REL%%")[1];return img.src;}function _gp(p){return p.substr(0,p.lastIndexOf("/")+1);}function xrep(s,f,n){if(s) s=s.split(f).join(n);return s;}InitRelCode();
</script>
<script type="text/javascript">
/* <![CDATA[ */function LoadMenus() {if(!rjsPath){window.setTimeout("LoadMenus()", 10);return false;}var navVer = navigator.appVersion;
if(navVer.substr(0,3) >= 4)
if((navigator.appName=="Netscape") && (parseInt(navigator.appVersion)==4)) {
document.write('<' + 'script type="text/javascript" src="' + rjsPath + 'nsmenu.js"><\/script\>');
} else {
document.write('<' + 'script type="text/javascript" src="' + rjsPath + 'iemenu.js"><\/script\>');
}return true;}LoadMenus();/* ]]> */</script>
<!-- DHTML Menu Builder Loader Code END -->

<table width="960" border="0" align="center" cellpadding="0" cellspacing="0" class="kant">
  <tr>
    <td><div align="center"></div>
    </td>
  </tr>
  <tr>
    <td><!-- InstanceBeginEditable name="toplogo" -->
      <table width="960" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
    <!-- InstanceEndEditable --></td>
  </tr>
  <tr>
    <td height="35"><div align="right"></div></td>
  </tr>
  <tr>
    <td><div align="right">
      <!-- InstanceBeginEditable name="brodtekst3" -->
      <table width="779" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>&nbsp;
            <form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
              <table align="center">
                <tr valign="baseline">
                  <td colspan="2" align="right" nowrap><div align="left">
                      <input name="vejretID" type="hidden" id="vejretID" />
                  </div></td>
                  <td colspan="9"><div align="left"><strong>Opret vejret </strong></div></td>
                </tr>
                <tr valign="baseline">
                  <td colspan="2" align="right" nowrap><div align="left"><strong>Vejret Dato:</strong></div></td>
                  <td colspan="9"><div align="left">
                   
                   
                      <input type="text" name="vejrdato" value="<%=date%>" size="12" />
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td colspan="2" align="right" nowrap><div align="left"><strong>Vejr Overskrift : </strong></div></td>
                  <td colspan="9"><div align="left">
                      <input type="text" name="vejrover" size="40" />
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td colspan="2" align="right" valign="top" nowrap><div align="left"><strong>Vejr Tekst: </strong></div></td>
                  <td colspan="9" valign="top"><div align="left" class="kant">
                      <textarea dmxedit="true" id="vejrtekst" name="vejrtekst" style="width:70%;height:250px;" config="language:da"></textarea>
                  </div></td>
                </tr>
                <tr valign="baseline">
                  <td width="100" align="right" nowrap>&nbsp;</td>
                  <td width="75" align="right" nowrap>&nbsp;</td>
                  <td width="100" align="right" nowrap>&nbsp;</td>
                  <td width="75" align="right" nowrap>&nbsp;</td>
                  <td width="120" align="right" nowrap>&nbsp;</td>
                  <td width="75" align="right" nowrap>&nbsp;</td>
                  <td width="100" align="right" nowrap>&nbsp;</td>
                  <td width="75" align="right" nowrap>&nbsp;</td>
                  <td colspan="3" align="right" nowrap><div align="left"></div></td>
                </tr>
                <tr valign="baseline">
                  <td width="100" align="right" nowrap></td>
                  <td width="75" align="right" nowrap>&nbsp;</td>
                  <td width="100" align="right" nowrap><input type="submit" value="Opret vejr" /></td>
                  <td width="75" align="right" nowrap>&nbsp;</td>
                  <td width="120" align="right" nowrap>&nbsp;</td>
                  <td width="75" align="right" nowrap>&nbsp;</td>
                  <td width="100" align="right" nowrap>&nbsp;</td>
                  <td width="75" align="right" nowrap>&nbsp;</td>
                  <td colspan="3" align="right" nowrap>&nbsp;</td>
                </tr>
              </table>
                           
             
           
             
           
             
           
              <input type="hidden" name="MM_insert" value="form1" />
            </form>
            <p>&nbsp;</p></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
      <!-- InstanceEndEditable --></div></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
<%
RSvejret.Close()
Set RSvejret = Nothing
%>
Avatar billede w13 Novice
03. februar 2008 - 15:37 #1
Det samme har jeg været ude fra. Jeg endte med at bruge funktionen:

function DBDate(sDate)
    DBDate=right("0"&month(sDate),2) &"-"& right("0"&day(sDate),2) &"-"& year(sDate)
end function

Så når jeg gemmer en data i db, skriver jeg f.eks.:

Conn.Execute("INSERT INTO table1 SET dato=#"&DBDate(now())&"#")
Avatar billede fc-dong Nybegynder
03. februar 2008 - 15:50 #2
Men hvordan skal den så skrives ind i koden hvor jeg indsætter datoen i databaseb
---------------------
<%
If (CStr(Request("MM_insert")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_ConnOuresport1_STRING
    MM_editCmd.CommandText = "INSERT INTO vejret (vejrdato, vejrover, vejrtekst) VALUES (?, ?, ?)"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 135, 1, -1, MM_IIF(Request.Form("vejrdato"), Request.Form("vejrdato"), null)) ' adDBTimeStamp
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 203, 1, 536870910, Request.Form("vejrover")) ' adLongVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 203, 1, 536870910, Request.Form("vejrtekst")) ' adLongVarWChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    ' append the query string to the redirect URL
    Dim MM_editRedirectUrl
    MM_editRedirectUrl = "vejret_aendre.asp"
    If (Request.QueryString <> "") Then
      If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
        MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
      Else
        MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
      End If
    End If
    Response.Redirect(MM_editRedirectUrl)
  End If
End If
%>
-------------------------------------
Avatar billede w13 Novice
03. februar 2008 - 16:00 #3
Tjaeh, umiddelbart ville jeg mene, du skal rette:

MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 135, 1, -1, MM_IIF(Request.Form("vejrdato"), Request.Form("vejrdato"), null)) ' adDBTimeStamp


til:

MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 135, 1, -1, MM_IIF(Request.Form("vejrdato"), DBDate(Request.Form("vejrdato")), null)) ' adDBTimeStamp
Avatar billede w13 Novice
28. april 2008 - 15:44 #4
Kommet videre?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester



Seneste spørgsmål Seneste aktivitet
I dag 06:10 Excel åbner fil i kæmpe format Af Aske i Excel
I går 22:00 Datafordeler Af Lsk i PHP
I går 12:37 Summere beløb pr. dato Af TTA i Excel
31/1022:44 Tilslutte chassic fans Af viking69 i PC
31/1020:28 LED lysstofrør Af ErikHg i Fri debat