| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 774 人关注过本帖
标题:修改数据库里的数据SQL语法错误.???!
只看楼主 加入收藏
飞石
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2007-3-10
收藏
 问题点数:0 回复次数:1 
修改数据库里的数据SQL语法错误.???!
现在我做了两个页面。第一个updata_list.aspx用了一个标签接受来自数据库的数据,并按照标题显示出来,代码如下。没有错误.
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.OleDb;

public partial class update_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string constring = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath(".") + "//db.mdb";
        OleDbConnection con = new OleDbConnection(constring);

        string sql = "select * from newsdb ";
        OleDbCommand com = new OleDbCommand(sql, con);
        com.Connection.Open();
        OleDbDataReader dr;
        dr = com.ExecuteReader();

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<table   ");

        while (dr.Read())
        {
            sb.Append("<tr> <td><a href='update.aspx?id=" + dr[0] + "'>" + dr[1] + "</a></td></tr>");
        }
        sb.Append("</table>");
        Label1.Text = sb.ToString();

    }
}
然后又建立了一个页面updata.aspx.接受来自updata_list.aspx的id值,并且想修改数据。但被提示SQL语法错误!请大家帮忙看看哪个地方出错了!!谢谢了~~~updata.aspx代码如下:
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.OleDb;

public partial class update : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string cid = Request.QueryString["id"];

        string constring = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath(".") + "//db.mdb";
        OleDbConnection con = new OleDbConnection(constring);

        string sql = "select * from newsdb where id= " + cid;
        OleDbCommand com = new OleDbCommand(sql, con);
        com.Connection.Open();
        OleDbDataReader dr;
        dr = com.ExecuteReader();

        while (dr.Read())
        {
           TextBox1.Text  = dr[1].ToString();
        TextBox2.Text  = dr[2].ToString();
            TextBox3.Text  = dr[3].ToString();
          TextBox4.Text  = dr[4].ToString();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        string constring = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath(".") + "//db.mdb";
        OleDbConnection con = new OleDbConnection(constring);
        con.Open();

        string sql = "update newsdb set title='" + TextBox1.Text + "', set sj='" + TextBox2.Text + "',set come='" + TextBox3.Text + "',set content='" +

TextBox4.Text + "' ";
        Response.Write(sql );

        OleDbCommand com = new OleDbCommand(sql, con);
        com.ExecuteNonQuery();

        Panel1.Visible = false;
        Panel2.Visible = true;
        Label1.Text = "新闻修该成功!";

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("update_list.aspx");
    }
}
搜索更多相关主题的帖子: SQL 数据库 语法 
2007-12-10 21:34
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
收藏
得分:0 
string sql = "update newsdb set title='" + TextBox1.Text.Trim() + "', sj='" + TextBox2.Text.Trim() + "',come='" + TextBox3.Text.Tirm() + "', content='" +TextBox4.Text + "' ";

不需要那么多set 吧

Flying without wings
2007-12-15 00:23
快速回复:修改数据库里的数据SQL语法错误.???!
数据加载中...
 
   



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

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