| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3787 人关注过本帖
标题:求助GridView不能更新,哪位大虾帮我看一下
取消只看楼主 加入收藏
yph1331
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-11-6
收藏
 问题点数:0 回复次数:2 
求助GridView不能更新,哪位大虾帮我看一下
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 weblibrary.data;

public partial class _Default : System.Web.UI.Page
{
    private SqlDataAdapter da;
    private DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        getInfo();
      
    }

    private void getInfo()
    {
        string str = "Data Source = .;Initial Catalog = library; User Id = sa;Password = 123";
        string sql = "select * from LB_FLXX";
        SqlConnection conn = new SqlConnection(str);
        da = new SqlDataAdapter(sql, conn);
        da.Fill(ds, "t");
        GridView1.DataSource = ds.Tables["t"];
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        getInfo();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        SqlCommandBuilder cb = new SqlCommandBuilder(da);
        da.Update(ds, "t");
        GridView1.EditIndex = -1;
        getInfo();
    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        getInfo();
    }
}

[[it] 本帖最后由 yph1331 于 2008-11-6 14:04 编辑 [/it]]
搜索更多相关主题的帖子: GridView 
2008-11-06 13:59
yph1331
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-11-6
收藏
得分:0 
问题已解决谢谢
2008-11-07 09:39
yph1331
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-11-6
收藏
得分:0 
现在用的是:
string sql = "update LB_FLXX set L_FLMC = @L_FLMC where L_FLBH = @L_FLBH";
        SqlCommand cmd = new SqlCommand(sql, conn);
        string name = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[1].FindControl("TextBox2"))).Text.Trim();
        int num = Convert.ToInt32(((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[0].FindControl("TextBox1"))).Text.Trim());
        cmd.Parameters.AddWithValue("@L_FLBH", num);
        cmd.Parameters.AddWithValue("@L_FLMC", name);
        try
        {
            conn.Open();
            cmd.ExecuteNonQuery();
        }
        catch
        {
            Response.Write("数据库操作失败!");
        }
        finally
        {
            conn.Close();
        }
        GridView1.EditIndex = -1;
        getInfo();
不过用  SqlCommandBuilder cb = new SqlCommandBuilder(da);
        da.Update(ds, "t");
还是不行,错误提示:未将对象引用设置到对象的实例
2008-11-07 10:05
快速回复:求助GridView不能更新,哪位大虾帮我看一下
数据加载中...
 
   



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

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