首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

将sql的数据显示在gridview中,更改了gridview中的数据,为什么sql中的数据不能更改?该怎么处理

2012-03-29 
将sql的数据显示在gridview中,更改了gridview中的数据,为什么sql中的数据不能更改?ProtectedSubGridView1_

将sql的数据显示在gridview中,更改了gridview中的数据,为什么sql中的数据不能更改?
Protected   Sub   GridView1_RowUpdated(ByVal   sender   As   Object,   ByVal   e   As   System.Web.UI.WebControls.GridViewUpdateEventArgs)   Handles   GridView1.RowUpdating
                Dim   connstring   As   SqlConnection
                connstring   =   New   SqlConnection( "data   source=yaozc;initial   catalog=ssenior;integrated   security=true ")
                '           Dim   connstring   As   String   =   "data   source=yaozc;initial   catalog=ssenior;integrated   security=true "
                Dim   sqlstring   As   String   =   "select   *   from   examfinish "
                Dim   sqldataadapter1   As   New   SqlDataAdapter(sqlstring,   connstring)
                connstring.Open()
                Dim   dataset1   As   New   DataSet()
                sqlstr   =   "UPDATE   examfinish   SET   remark   =   @remark   "   +   "WHERE   name   =   @name "
                sqldataadapter1.Fill(dataset1,   "examfinish ")
                sqldataadapter1.UpdateCommand   =   New   SqlCommand(sqlstr,   connstring)
                sqldataadapter1.UpdateCommand.Parameters.Add( "@remark ",   SqlDbType.NVarChar,   20,   "remark ")
                sqldataadapter1.UpdateCommand.Parameters.Add( "@name ",   SqlDbType.NVarChar,   20,   "name ")
                sqldataadapter1.Update(dataset1,   "examfinish ")
                GridView1.DataSource   =   dataset1.Tables( "examfinish ").DefaultView
                GridView1.DataBind()
                connstring.Close()


[解决办法]
Protected Sub GridView2_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView2.RowUpdating


If IsNumeric(CType(GridView2.Rows(e.RowIndex).FindControl( "TextBox3 "), TextBox).Text) = False Then
Response.Write( " <script language=javascript> alert( '必须输入数字!! ');history.go(-1) </script> ")
Response.End()
End If

Dim conn As String = System.Configuration.ConfigurationManager.ConnectionStrings( "znhConnectionStringall ").ToString

Dim comm As SqlCommand
comm = New SqlCommand( "update cust_item set item_xcpage= ' " & CType(GridView2.Rows(e.RowIndex).FindControl( "TextBox4 "), TextBox).Text & " ',item_jzpage= ' " & CType(GridView2.Rows(e.RowIndex).FindControl( "TextBox5 "), TextBox).Text & " ',item_tsyq= ' " & CType(GridView2.Rows(e.RowIndex).FindControl( "TextBox6 "), TextBox).Text & " ',item_num= ' " & CType(GridView2.Rows(e.RowIndex).FindControl( "TextBox3 "), TextBox).Text & " ',rapid_time= ' " & CType(GridView2.Rows(e.RowIndex).FindControl( "TextBox1 "), TextBox).Text & " ' where custitem_id= ' " & CType(GridView2.Rows(e.RowIndex).FindControl( "CheckBox1 "), CheckBox).Text & " ' ", New SqlClient.SqlConnection(conn))



comm.Connection.Open()
comm.ExecuteNonQuery()

GridView2.EditIndex = -1

Dim sql1 As String = "select custitem_id,custdo_id,item_type,item_name,item_size,item_xcpage,item_jzpage,item_tsyq,item_num,item_price,item_ok,cp,p_time,mem_gh,moyw,convert(varchar,rapid_time,2)rapid_time from cust_item where item_ok=0 and custdo_id= ' " & Session( "id ") & " ' "

Dim adapter1 As New SqlDataAdapter(sql1, conn)
Dim dataset1 As New DataSet
adapter1.Fill(dataset1)

GridView2.DataSource = dataset1.Tables(0)
GridView2.DataBind()
End Sub

热点排行