| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1325 人关注过本帖
标题:[求助]连接数据库出错!!
取消只看楼主 加入收藏
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
结帖率:100%
收藏
 问题点数:0 回复次数:10 
[求助]连接数据库出错!!

存放数据库文件夹database和文件在同一级目录,运行文件的错误代码如下:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'MyConn' does not exist in the class or namespace 'ASP.editcommandcolumn_aspx'

Source Error:

Line 14: //连接词句
Line 15: string Myconnstring = " Provider=Micorsoft.Jet.LOEDB.4.0; Data Source="+Server.MapPath(".")+" ..\\DataBase\\db1.mdb;";
Line 16: MyConn=new OleDbConnection (MyConnString);
Line 17: MyConn.open();
Line 18:

请帮忙解决,谢谢!!

搜索更多相关主题的帖子: 数据库 Line The 
2006-09-13 16:40
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 

失败,不行呀


2006-09-13 16:51
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 
晕了,不行,好象不是路径错误,你们看一下代码哪有没有问题

2006-09-13 17:01
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 

按第5楼的说法,现在错误代码成下面这样了:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1002: ; expected

Source Error:

Line 13: {
Line 14: //连接词句
Line 15: string MyConnString = " Provider=Micorsoft.Jet.LOEDB.4.0; Data Source="Server.MapPath("//")+"DataBase\\db1.mdb";
Line 16: MyConn=new OleDbConnection (MyConnString);
Line 17: MyConn.open();

Source File: F:\123456\editcommandcolumn.aspx Line: 15


2006-09-13 17:17
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 

晕死了,还是不行,直接复制你的代码换掉又出现一楼上的错误了


2006-09-13 17:38
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 

晕了,下面是原代码:
<script language="C#" runat="server">
OleDbConnection MyConn;
public void Page_Load(Object src,EventArgs e)
{
//连接词句
string MyConnString = " Provider=Micorsoft.Jet.LOEDB.4.0; Data Source="+Server.MapPath("//")+"DataBase\\db1.mdb";
MyConn=New OleDbConnection(MyConnString);
MyConn.open();

if (!Page.IsPostBack)
{
BingdGrid();
}
}
ICollection CreateTable()
{
string strsel="select * form score";
Dateset ds=new Dateset();
OleDbDataAdapter MyAdapter=new OleDbDataAdapter(strsel,Myconn);
MyAdapter.Fill(ds."score");
return ds.Tables("score").DefaultView;
}
public void BindGrid()
{
score.Datasource=CreateTable();
score.DataBind();
}

//处理EDIT命令
public void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemIndex=(int)e.Item.Itemindex;
BindGrid();
}
//处理Cancel命令
public void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemindex=-1;
BindGrid();
}
//处理update命令
public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息
string strname=e.Item.Cells[1].Text;
int intChinese=
Int32.parse(((Textbox)e.Item.Cells[2].Controls[0]).Text);
int intMath=
Int32.Parse(((Textbox)e.Item.Cells[3].Controls[0]).Text);
int intEnglish=
Int32.Parse(((Textbox)e.Item.Cells[4].Controls[0]).Text);
//更新数据库的数据
string strupdate="update score set chinese="+intchinese+",math="+intmath+",endlish="+intenglish+" where name=''"+strname+"";
OleDbCommand mycomm=new OledbCommmand(strupdate,myconn);
mycomm.executenonquery();
score.editItemindex=-1;
bindgrid();

}
</script>


2006-09-13 17:44
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 

不行的,现在也下班了,明天没事时帮我测试一下,我从书上原样写的代码,不知哪里不行,谢谢,下面是全部代码:
<%@ Page Language="C#" %>
<% @ import namespace="System.Data" %>
<% @ import namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
public OleDbConnection MyConn;
public void Page_Load(Object src,EventArgs e)
{
//连接词句
string MyConnString = " Provider=Micorsoft.Jet.LOEDB.4.0; Data Source="+Server.MapPath("//")+"DataBase\\db1.mdb";
MyConn=New OleDbConnection(MyConnString);
MyConn.open();

if (!Page.IsPostBack)
{
BingdGrid();
}
}
ICollection CreateTable()
{
string strsel="select * form score";
Dateset ds=new Dateset();
OleDbDataAdapter MyAdapter=new OleDbDataAdapter(strsel,Myconn);
MyAdapter.Fill(ds."score");
return ds.Tables("score").DefaultView;
}
public void BindGrid()
{
score.Datasource=CreateTable();
score.DataBind();
}

//处理EDIT命令
public void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemIndex=(int)e.Item.Itemindex;
BindGrid();
}
//处理Cancel命令
public void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemindex=-1;
BindGrid();
}
//处理update命令
public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息
string strname=e.Item.Cells[1].Text;
int intChinese=
Int32.parse(((Textbox)e.Item.Cells[2].Controls[0]).Text);
int intMath=
Int32.Parse(((Textbox)e.Item.Cells[3].Controls[0]).Text);
int intEnglish=
Int32.Parse(((Textbox)e.Item.Cells[4].Controls[0]).Text);
//更新数据库的数据
string strupdate="update score set chinese="+intchinese+",math="+intmath+",endlish="+intenglish+" where name=''"+strname+"";
OleDbCommand mycomm=new OledbCommmand(strupdate,myconn);
mycomm.executenonquery();
score.editItemindex=-1;
bindgrid();

}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
<center>
<b>演示editcommmandcloumn</b>
<asp:DataGrid id="score" runat="server"
headerstyle-backcolor="#aaaadd"
alternatingitemstyle-backcolor="#eeeeee"
autogeneratecolumns="false"
oneditcommand="DataGrid_Editcommand"
onUpdateCommand="DataGrid_UpdateCommand"
onCancelCommand="FataGrid_CancelCommand">
<Columns>
<asp:EditCommandColumn HeaderText="操作区"
EditText="编辑"
UpdateText="更新"
CancelText="取消"
ButtonType="PushButton" />
<asp:BoundColumn HeaderText="姓名" DataField="name" Readonly="true" />
<asp:BoundColumn HeaderText="语文" DataField="Chinese" />
<asp:BoundColumn HeaderText="数学" DataField="Math" />
<asp:BoundColumn HeaderText="英语" DataField="English" />
</Columns>
</asp:DataGrid>
</center>
</form>
</body>
</html>


2006-09-13 18:03
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 
name=''"+strname+"";修改为 name='"+strname+"';是吗,不行呀,还是提示MyConn=New OleDbConnection(MyConnString); 这个错误!!

2006-09-14 10:28
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 

不行呀,晕死,楼上的朋友帮忙把上面的代码复制到你本地调试一下,我新手,从教材上写下来的,无法运行就更搞不明白了!!


2006-09-14 10:52
35maoe
Rank: 1
等 级:新手上路
帖 子:341
专家分:0
注 册:2006-8-28
收藏
得分:0 

呵呵,谢谢,chenjin145找到一个关键的地方,修改后还是不行,又修改了大小写,总算跳过去了,现在body里的最后几步又出氏,唉,晕死,错误代码不同,:
No error information available: REGDB_E_CLASSNOTREG(0x80040154).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: No error information available: REGDB_E_CLASSNOTREG(0x80040154).

看一下这是什么意思??


2006-09-14 14:28
快速回复:[求助]连接数据库出错!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016972 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved