| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 770 人关注过本帖
标题:C#删除DBF中的记录不成功,请大家指教
只看楼主 加入收藏
lovestanford
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2009-8-2
收藏
 问题点数:0 回复次数:0 
C#删除DBF中的记录不成功,请大家指教
C#删除DBF中的记录不成功,请大家指教

打开一个DBF数据文件后将数据绑定到一个Gridview中显示,同时给Gridview增加了删除事件的处理来删除文件中的某一行,问题是删除不了,出现下面的错误:ERROR [42000] [Microsoft][ODBC Visual FoxPro Driver]Syntax error.
前台代码:
<html xmlns="http://www. >
<head runat="server">
    <title>本科单位数据导入</title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="main" style="width:100%; height:700px; background-color:#DEDFD">
    <table>
    <tr><td style="width: 179px; height: 23px;">
        <asp:FileUpload ID="FileUpload1" runat="server" Height="28px" Width="225px" /></td><td style="width: 188px; height: 23px;">
        <asp:Button ID="Button1" runat="server" Height="33px" OnClick="Button1_Click" Text="预览数据"
            Width="116px" /></td><td style="width: 295px; height: 23px">
        <asp:Button ID="Button2" runat="server" Height="31px" Text="导入表中" Width="123px" OnClick="Button2_Click" /></td><td style="width: 411px; height: 23px;">
        <input id="Hidden1" runat="server" style="height: 25px" type="hidden" /></td>
    </tr>
    <tr><td style="width: 172px; height: 603px;" colspan="4">
         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"
            BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
            GridLines="None" Height="589px" Width="1152px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound">
            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
            <Columns>
                <asp:BoundField  DataField="BYDWDM" HeaderText="本科单位代码"/>
                <asp:BoundField  DataField="BYDWMC" HeaderText="本科单位名称"/>
                <asp:BoundField DataField="SZSSM" HeaderText="所在省市码"/>
                <asp:BoundField DataField="SZSS" HeaderText="所在省市"/>
                <asp:BoundField DataField="OLDDWDM" HeaderText="旧代码"/>
                <asp:BoundField DataField="OLDDWMC" HeaderText="旧名称"/>
                <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
            </Columns>
            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            <PagerSettings FirstPageText="首页" LastPageText="尾页" Mode="NextPreviousFirstLast"
                NextPageText="下一页" PreviousPageText="上一页" />
        </asp:GridView>
    </td>
    </tr>
   
    </table>
        </div>
    </form>
</body>
</html>
后台代码如下:
private void bind_gridview()
    {
        DataTable ta = new DataTable();
        string data_source = Hidden1.Value.ToString();
        ta = toracle.DBTable(@data_source);
        GridView1.DataSource = ta;
        GridView1.DataKeyNames = new string[] { "BYDWDM" };
        GridView1.DataBind();
    }
//绑定GridView
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string sava_dbf_path =Hidden1.Value.ToString();
        string dbf_connectionstring = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" +@sava_dbf_path + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO";
        System.Data.Odbc.OdbcConnection del_conn = new OdbcConnection();
        string keys = GridView1.DataKeys[e.RowIndex].Value.ToString();
       // string del_sql = "delete from"+ @sava_dbf_path + "where BYDWDM ='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        string del_sql = "delete from " + @sava_dbf_path + "where Bydwdm=" + keys;
//sava_dbf_path=F:\09省考试院\dmbkdw本科单位.dbf
        del_conn.ConnectionString = dbf_connectionstring;
        
        try
        {
            del_conn.Open();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        OdbcCommand comm = new OdbcCommand();
        comm.Connection = del_conn;
         = del_sql;
         = CommandType.Text;
        
        try
        {
            comm.ExecuteNonQuery();
        }
        catch (Exception excep)
        {
            throw excep;
        }
        if (this.GridView1.Rows.Count == 1 && this.GridView1.PageIndex > 0)
        {
            this.GridView1.PageIndex--;
        }
        bind_gridview();
    }
请高手指导
搜索更多相关主题的帖子: DBF 记录 指教 删除 
2009-08-03 16:40
快速回复:C#删除DBF中的记录不成功,请大家指教
数据加载中...
 
   



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

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