日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

asp.net使用GridView刪除更新ACCESS數(shù)據(jù)庫里的數(shù)據(jù)問題!急!!!

 行走在理想邊緣 2019-02-15
一個網(wǎng)站先前用的是MS-SQL現(xiàn)在更換數(shù)據(jù)庫 為ACCESS 

一個GridView里面有更新刪除 因為語法有點不一樣去做了修改 刪除修改好了沒什么問題..但是更新怎么也不行..老提示"語法錯誤 (操作符丟失) 在查詢表達式 'where id="

就是那一堆單引號,和雙銀號鬧的..大家?guī)臀铱纯?.謝謝啦!

數(shù)據(jù)庫 字段
    id    txt    date
------------------------
 自動編號 備注   time
代碼:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;

public partial class Admin_ad_jj : System.Web.UI.Page
{
    OleDbConnection con = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + " C:/Documents and Settings/AndersoN/桌面/xf/database/xf.mdb");
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        this.TextBox1.Text = "";
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
       
        con.Open();
        string ad_news = "insert into jj (txt)values('" + this.TextBox1.Text + "')";
        OleDbCommand com = new OleDbCommand(ad_news, con);
        com.ExecuteNonQuery();
        con.Close();
        bind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        con.Open();
        string sqlstr = "update jj set txt="+((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim()+"where id="+Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString())+"";
        
        OleDbCommand sqlcom = new OleDbCommand(sqlstr, con);
        sqlcom.ExecuteNonQuery();
        con.Close();
        GridView1.EditIndex = -1;
        bind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        con.Open();
        string sqlstr = "delete from jj where id=" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()) + "";
        OleDbCommand com = new OleDbCommand(sqlstr, con );
        com.ExecuteNonQuery();
        con.Close();
        bind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind();
    }
    public void bind()
    {
        string sqlstr = "select * from jj";
        OleDbCommand myda = new OleDbCommand(sqlstr, con);
        con.Open();
        this.GridView1.DataSource = myda.ExecuteReader(); 
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
        con.Close();
    }
}
在樂山,還在拿三四千工資?試試這個,收入提高好幾倍! 廣告 無極道 · 鹓鶵

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多