佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 4973|回复: 128

.net 求救 (Server.MapPath)

[复制链接]
发表于 24-7-2006 03:08 PM | 显示全部楼层 |阅读模式
求救。。我是C#新手,试了整天,还是connect不到去database。。请帮忙看看,问题出在哪里。。ReqDBConn = new SqlConnection(ConnStr); 不对吗?

public class DataServer
        {
                private SqlConnection ReqDBConn;
                private const string ConnStr = @"Provider=Microsoft.Jet.OLEDB.4.0;data
source=db_ncmr.mdb";
        
                public string LogIn(string strUserID, string strUserPwd)
                {
                        try
                        {
                                ReqDBConn = new SqlConnection(ConnStr);
                                                        
                                return “Success”;

                        }
                        catch(Exception e)
                        {
                                return(Convert.ToString(e));
                        }        
                }
        }

[ 本帖最后由 shinelynn 于 10-10-2007 02:39 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 24-7-2006 06:45 PM | 显示全部楼层
SQLConnection 是给 sql server 用的, 你应该用 odbcconnection. 另外, 你的 code 不完整. 查看 .Net Framework 的 manual 吧.
回复

使用道具 举报

 楼主| 发表于 24-7-2006 06:55 PM | 显示全部楼层
原帖由 goatstudio 于 24-7-2006 06:45 PM 发表
SQLConnection 是给 sql server 用的, 你应该用 odbcconnection. 另外, 你的 code 不完整. 查看 .Net Framework 的 manual 吧.


谢谢,已经换去oleDbConnetion了。。

呵呵,我上面的code只是想test connection罢了,log in screen已经可以运作了,
谢谢。。

另外想问,假如我想在一个.aspx的file里面include另一个.aspx的file,该如何做
呢?因为我这么做。。有error。。

[ 本帖最后由 shinelynn 于 24-7-2006 07:45 PM 编辑 ]
回复

使用道具 举报

发表于 25-7-2006 09:04 AM | 显示全部楼层
要看你如何写... error message 是什么呢?
回复

使用道具 举报

 楼主| 发表于 25-7-2006 10:34 AM | 显示全部楼层
原帖由 goatstudio 于 25-7-2006 09:04 AM 发表
要看你如何写... error message 是什么呢?


奇怪我现在试又可以了。。 昨天的error msg是什么one page cannot have more than one redirect page 。。或什么的。。可是现在又可以了。。<!--#include file="menu.aspx" -->

谢谢。。
回复

使用道具 举报

 楼主| 发表于 25-7-2006 01:36 PM | 显示全部楼层
哎呀,我很blur,刚才因为我remove掉了其中一个page的
<%@ Page language="c#" Codebehind="menu.aspx.cs" AutoEventWireup="false" Inherits="NCMR.menu" %> ,所以没有error,其实error还在。。

我要在我的mainmenu.aspx 加入menu.aspx 来做header,我的menu.aspx也要写coding,因为不同level access的user用系统时,我就会disable掉一些menu。。

Parser Error Message: There can be only one 'page' directive.

mainmenu.aspx
<%@ Page language="c#" Codebehind="mainmenu.aspx.cs" AutoEventWireup="false"
Inherits="NCMR.mainmenu" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
       
        <body MS_POSITIONING="GridLayout">
                <form id="Form1" method="post" runat="server">
                        <TABLE id="Table2" height="37" cellSpacing="0" cellPadding="0" width="100%
" border="0">
                                <TR>
                                        <TD width="20%" bgColor="#ffffff"><asp:label id="lblUser" runat="server"
Font-Italic="True" Font-Size="X-Small"></asp:label></TD>
                                        <TD width="20%" bgColor="#ffffff"><A href="main.aspx">Log Out</A></TD>
                                </TR>
                        </TABLE>
                        <!--#include file="menu.aspx" -->
                   </form>
        </body>
</HTML>

啊。。救命
回复

使用道具 举报

Follow Us
发表于 25-7-2006 01:44 PM | 显示全部楼层
你的 menu.aspx 里有什么呢?
回复

使用道具 举报

 楼主| 发表于 25-7-2006 02:39 PM | 显示全部楼层
<%@ Page language="c#" Codebehind="menu.aspx.cs" AutoEventWireup="false" Inherits="NCMR.menu" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
        <HEAD>
                <style>
        BODY { FONT-FAMILY: arial }
        TABLE { FONT-SIZE: 80%; BACKGROUND: black }
        A { FONT-WEIGHT: bold; COLOR: black; TEXT-DECORATION: none }
        A:hover { COLOR: #606060 }
        TD.menu { BACKGROUND: #ccffff }
        TABLE.menu { FONT-SIZE: 100%; VISIBILITY: hidden; POSITION: absolute }
                </style>
                <script type="text/javascript">
                function showmenu(elmnt)
                {
                        document.getElementById(elmnt).style.visibility="visible"
                }
                function hidemenu(elmnt)
                {
                        document.getElementById(elmnt).style.visibility="hidden"
                }
                </script>
        </HEAD>
        <body MS_POSITIONING="GridLayout">
                <form id="Form1" method="post" runat="server">
                        <table id="Table1" cellSpacing="1" cellPadding="1" width="100%" bgColor="lightblue" border="1">
                                <tr bgColor="#ff8080">
                                        <td onmouseover="showmenu('ncmr')" onmouseout="hidemenu('ncmr')" width="25%" bgColor="#6699ff">TESTING<br>
                                                <table class="menu" id="ncmr" width="120">
                                                        <tr>
                                                                <td class="menu">
                                                                        <asp:HyperLink id="hl1" runat="server">TESTING 1</asp:HyperLink></td>
                                                        </tr>
                                                        <tr>
                                                                <td class="menu">
                                                                        <asp:HyperLink id="hl2" runat="server">TESTING 2</asp:HyperLink></td>
                                                        </tr>
                                                        <tr>
                                                                <td class="menu">
                                                                        <asp:HyperLink id="hl3" runat="server">TESTING 3</asp:HyperLink></td>
                                                        </tr>
                                                        <tr>
                                                                <td class="menu">
                                                                        <asp:HyperLink id="hl4" runat="server">TESTING 4</asp:HyperLink></td>
                                                        </tr>
                                                        <tr>
                                                                <td class="menu">
                                                                        <asp:HyperLink id="hl5" runat="server">TESTING 5</asp:HyperLink></td>
                                                        </tr>
                                                </table>
                                        </td>
                                </tr>
                        </table>
                </form>
        </body>
</HTML>

我这样paste进来不知道你看了会不会晕。。

我上网查,应该是一个page不可以有两个<%@ Page .. %>,因为我把一个.aspx的file include进另一个.aspx 的file,所以总共有2个<%@ Page .. %>了。。

我想用frame,可是因为这是drop down menu,frame会把drop down遮住了。。所以我还是要用include file,假如。。真的没办法的话,只好把menu的code加进每一个.aspx的file了。。
回复

使用道具 举报


ADVERTISEMENT

发表于 25-7-2006 06:30 PM | 显示全部楼层
可以用 user control来做啊
回复

使用道具 举报

 楼主| 发表于 26-7-2006 07:47 AM | 显示全部楼层
原帖由 石破天金 于 25-7-2006 06:30 PM 发表
可以用 user control来做啊


什么来的? 我去网上看看。。
回复

使用道具 举报

 楼主| 发表于 26-7-2006 09:51 AM | 显示全部楼层
用了web user control,可以了,谢谢大家。。。
回复

使用道具 举报

 楼主| 发表于 27-7-2006 06:48 PM | 显示全部楼层
不知道哪里错了。。我已经查了我的sql statement,没有错啊,可是还是insert 不
到。。

INSERT INTO TBL_USER VALUES('123','123','123','Main Store','123','123','123@123.
com')

public string CreateUser(string strsql)
                {
                        try
                        {
                                ReqDBConn = new OleDbConnection(ConnStr);
                                ReqDBConn.Open();
                                ReqDBCmd = new OleDbCommand(strsql,ReqDBConn);
                                ReqDBCmd.ExecuteNonQuery();
                                ReqDBConn.Close();

                                return "Success";
                        }
                        catch(Exception ex)
                        {
                                return ex.ToString();
                                //return strsql;
                        }

Error message:

System.Data.OleDb.OleDbException: Operation must use an updateable query.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32
hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(
Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior
behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(
CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery(
) at NCMR.DataServer.CreateUser(String strsql) in d:\supplier\ncmr\dataserver.
cs:line 121
回复

使用道具 举报

发表于 29-7-2006 11:06 PM | 显示全部楼层
原帖由 shinelynn 于 27-7-2006 06:48 PM 发表
不知道哪里错了。。我已经查了我的sql statement,没有错啊,可是还是insert 不
到。。

INSERT INTO TBL_USER VALUES('123','123','123','Main Store','123','123','123@123.
com')

public string Create ...

DATABASE的DATATYPE是不是全部是TEXT???
FIELD的数量对吗??
回复

使用道具 举报

 楼主| 发表于 30-7-2006 11:00 AM | 显示全部楼层
全是text,我在ms access 的 query里run这sql没问题。。 我上网查别人都是这么写的啊。。
回复

使用道具 举报

发表于 30-7-2006 11:33 AM | 显示全部楼层
'123@123.com'

试试那掉这个@
回复

使用道具 举报

发表于 31-7-2006 09:30 AM | 显示全部楼层
原帖由 shinelynn 于 30-7-2006 11:00 AM 发表
全是text,我在ms access 的 query里run这sql没问题。。 我上网查别人都是这么写的啊。。


你用 access 吧?
从 error message 看来... 是你的 access file 的用户权限的问题.
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 31-7-2006 05:01 PM | 显示全部楼层
@和没有@都不可以,可能是read/write的问题,因为可以select,不可以insert,update和delete,找负责server的同事,他不听我电话。。
回复

使用道具 举报

发表于 1-8-2006 12:14 AM | 显示全部楼层
http://support.microsoft.com/kb/175168/EN-US/

很多时候我遇到新的error message,我都回直接用那个error message来search,很快就会找到解决方案了
回复

使用道具 举报

发表于 1-8-2006 12:23 AM | 显示全部楼层
原帖由 goatstudio 于 31-7-2006 09:30 AM 发表


你用 access 吧?
从 error message 看来... 是你的 access file 的用户权限的问题.

是SECURITY那边吗??
只能READONLY吗???
回复

使用道具 举报

 楼主| 发表于 1-8-2006 08:43 AM | 显示全部楼层
http://support.microsoft.com/kb/175168/EN-US/
这好用,save进favorite了。。

解决了,是read/write的问题,我以为是folder的read/write,所以便向server的人要求write的access,可是原来是ms access那里的security。。

又学了一样东西。。谢谢大家帮忙。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 19-9-2025 05:19 AM , Processed in 0.123367 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表