how to get the code in gridveiw for the single column is having with each row one button and textbox which i m fing hard to get the updation in the database table only one row is getting updated ..plz help........
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Data.SqlClient.SqlCommand
Partial Class RoomAvailable Inherits System.Web.UI.Page Dim con As SqlConnection Dim ds As New DataSet Dim cmd As New SqlCommand Dim adp As New SqlDataAdapter Dim sql As String Dim sql1 As String
Sub conn() con = New SqlConnection("Data Source=192.168.0.109;Initial Catalog=HostelDB;User ID=sa;password=T102t2a1l")
If con.State = ConnectionState.Closed Then
End If con.Open() End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Call conn() If Not IsPostBack Then
sql = "select * from BedAvailable1" adp = New SqlDataAdapter(sql, con) adp.Fill(ds) GridView1.DataSource = ds GridView1.DataBind() End If End Sub
Protected Sub btncalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncalculate.Click Dim a1, a2 As String Dim b1, b2 As Integer
Dim BedOccupied, BedOccupied1 As TextBox Dim RoomNo, RoomNo1 As Label
Dim i As Integer
For i = 0 To GridView1.Rows.Count - 1 BedOccupied = CType(GridView1.Rows(0).Cells(0).FindControl("Textbox1"), TextBox) a1 = BedOccupied.Text RoomNo = CType(GridView1.Rows(0).Cells(0).FindControl("Label1"), Label) b1 = RoomNo.Text
' sql = "update BedAvailable1 set BedOccupied ='" & a1 & "' where RoomNo ='" & b1 & "' " 'sql = "update BedAvailable1 set BedOccupied ='" & a2 & "' where RoomNo ='" & b2 & "' " 'sql = "update BedAvailable1 set BedOccupied ='" & a3 & "' where RoomNo ='" & b3 & "' " 'sql = "update BedAvailable1 set BedOccupied ='" & a4 & "' where RoomNo ='" & b4 & "' " 'sql = "update BedAvailable1 set BedOccupied ='" & a5 & "' where RoomNo ='" & b5 & "' " 'sql = "update BedAvailable1 set BedOccupied ='" & a6 & "' where RoomNo ='" & b6 & "' " 'sql = "update BedAvailable1 set BedOccupied ='" & a7 & "' where RoomNo ='" & b7 & "' " 'sql = "update BedAvailable1 set BedOccupied ='" & a8 & "' where RoomNo ='" & b8 & "' " 'sql = "update BedAvailable1 set BedOccupied ='" & a9 & "' where RoomNo ='" & b9 & "' "
cmd = New SqlCommand(sql, con) cmd.ExecuteNonQuery()
End Sub End Class
--------------------Yesterdays code i have added in this way but its not working---------------------
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Data.SqlClient.SqlCommand
Partial Class RoomAvailable Inherits System.Web.UI.Page Dim con As SqlConnection Dim ds As New DataSet Dim cmd As New SqlCommand Dim adp As New SqlDataAdapter Dim sql As String Dim sql1 As String
Sub conn() con = New SqlConnection("Data Source=192.168.0.109;Initial Catalog=HostelDB;User ID=sa;password=T102t2a1l")
If con.State = ConnectionState.Closed Then
End If con.Open() End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Call conn() If Not IsPostBack Then
sql = "select * from BedAvailable1" adp = New SqlDataAdapter(sql, con) adp.Fill(ds) GridView1.DataSource = ds GridView1.DataBind() End If End Sub
Protected Sub btncalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncalculate.Click Dim a1, a2, a3, a4, a5, a6, a7, a8, a9 As String Dim b1, b2, b3, b4, b5, b6, b7, b8, b9 As Integer
Dim BedOccupied, BedOccupied1, BedOccupied2, BedOccupied3, BedOccupied4, BedOccupied5, BedOccupied6, BedOccupied7, BedOccupied8 As TextBox Dim RoomNo, RoomNo1, RoomNo2, RoomNo3, RoomNo4, RoomNo5, RoomNo6, RoomNo7, RoomNo8 As Label
Dim i As Integer
For i = 0 To GridView1.Rows.Count - 1 BedOccupied = CType(GridView1.Rows(i).Cells(0).FindControl("Textbox1"), TextBox) a1 = BedOccupied.Text RoomNo = CType(GridView1.Rows(i).Cells(0).FindControl("Label1"), Label) b1 = RoomNo.Text
praveen.chin...
None
0 Points
1 Post
gridview problem
Aug 05, 2011 11:43 AM|LINK
how to get the code in gridveiw for the single column is having with each row one button and textbox which i m fing hard to get the updation in the database table only one row is getting updated ..plz help........
-------------Source code----------
rkbvasanths@...
Participant
957 Points
236 Posts
Re: gridview problem
Aug 05, 2011 11:46 AM|LINK
For i = 0 To GridView1.Rows.Count - 1
BedOccupied = CType(GridView1.Rows(i).Cells(0).FindControl("Textbox1"), TextBox)
a1 = BedOccupied.Text
RoomNo = CType(GridView1.Rows(i).Cells(0).FindControl("Label1"), Label)
b1 = RoomNo.Text
sql = "update BedAvailable1 set BedOccupied = '" & a1 & "'where RoomNo ='" & b1 & "' "
BedOccupied1 = CType(GridView1.Rows(i+1).Cells(0).FindControl("Textbox1"), TextBox)
a2 = BedOccupied1.Text
RoomNo1 = CType(GridView1.Rows(i+1).Cells(0).FindControl("Label1"), Label)
b2 = RoomNo1.Text
sql1 = "update BedAvailable1 set BedOccupied = '" & a2 & "'where RoomNo ='" & b2 & "' "
Next
Thanks,
Vasanth R, MCTS(SQL 2005 & SQL 2008 BI), MCP
http://dotnetcodeguide.blogspot.com