报错,帮我看看

roopeman 2004-11-19 10:55:39
code:
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

// Insert page code here
//

void Btn_Add_Click(object sender, EventArgs e) {
string ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;"+
"Data Source=C:\\NaiYuan\\Db\\BigShop.mdb";
string CommandString = "Select * from Branch";
OleDbConnection MyConn = new OleDbConnection(ConnectionString);
OleDbDataAdapter MyAdapter = new OleDbDataAdapter(CommandString,MyConn);
DataSet MyData = new DataSet();
MyAdapter.Fill(MyData,"Branch");
//DataGrid1.DataSource = MyData.Tables["Branch"];
//DataGrid1.DataBind();
//add block
DataTable Branch_Table;
DataRow newRow;
Branch_Table = MyData.Tables["Branch"];
newRow = Branch_Table.NewRow();
newRow["Shop_Name"] = Tb_Name.Text;
newRow["Shop_Location"] = Tb_Location.Text;
Branch_Table.Rows.Add(newRow);
OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(MyAdapter);
MyAdapter.UpdateCommand = commandBuilder.GetUpdateCommand();
MyAdapter.InsertCommand = commandBuilder.GetInsertCommand();
MyAdapter.DeleteCommand = commandBuilder.GetDeleteCommand();
MyAdapter.Update(MyData,"Branch");
DataGrid1.DataSource = MyData.Tables["Branch"];
DataGrid1.DataBind();


}
//del block
void Btn_Del_Click(object sender, EventArgs e) {
Branch_Table.Rows[Branch_Table.Rows.Count-3].Delete();
MyAdapter.Update(MyData,"Branch");
DataGrid1.DataSource = MyData.Tables["Branch"];
DataGrid1.DataBind();
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Label id="Label1" runat="server">Shop Name</asp:Label>
<asp:TextBox id="Tb_Name" runat="server"></asp:TextBox>
<br />
<asp:Label id="Label2" runat="server">Shop Location</asp:Label>
<!-- Insert content here -->
<asp:TextBox id="Tb_Location" runat="server"></asp:TextBox>
<br />
<asp:Button id="Btn_Add" onclick="Btn_Add_Click" runat="server" Text="Add"></asp:Button>
 
<asp:Button id="Btn_Del" onclick="Btn_Del_Click" runat="server" Text="Del"></asp:Button>
 
<asp:Button id="Btn_Edit" runat="server" Text="Edit"></asp:Button>
 
<asp:Button id="Btn_Search" runat="server" Text="Search"></asp:Button>
<br />
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
</form>
</body>
</html>

//error message
erver Error in '/' Application.
--------------------------------------------------------------------------------

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: CS0246: The type or namespace name 'Branch_Table' could not be found (are you missing a using directive or an assembly reference?)

Source Error:



Line 37: //del block
Line 38: void Btn_Del_Click(object sender, EventArgs e) {
Line 39: Branch_Table.Rows[Branch_Table.Rows.Count-3].Delete();
Line 40: MyAdapter.Update(MyData,"Branch");
Line 41: DataGrid1.DataSource = MyData.Tables["Branch"];


Source File: NaiYuan\EBike\Branch.aspx Line: 39
...全文
117 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyy431706 2004-11-19
  • 打赏
  • 举报
回复

DataTable Branch_Table=new DataTable();//修改这行
DataRow newRow;
Branch_Table = MyData.Tables["Branch"];
newRow = Branch_Table.NewRow();
yyy431706 2004-11-19
  • 打赏
  • 举报
回复
DataTable Branch_Table=new DataTable();
roopeman 2004-11-19
  • 打赏
  • 举报
回复
修改后,还是不行!

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧