GridView Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweatha
    New Member
    • Mar 2008
    • 44

    GridView Problem

    Hi Friends

    I have designed a form with 2 label boxes, 2 text boxes & 1 command button. If I click the command button then, the value entered in the text boxes should be inserted in the db & at the same time it should display in the grid view. The platform is ASP.NET with SQL SERVER 2000.

    The coding I have given is
    [code=vbnet]

    Imports System.Data
    Imports System.Data.Sql Client
    '------------------------------------------------------------------------------------
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim dgcmd As SqlCommand
    Dim str, str1 As String
    Dim dgstr As String
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    '------------------------------------------------------------------------------------
    Protected Sub Button4_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button4.Click
    str = "user id=sa;password= ;data source=AURO-RA4;initial catalog=suganya ;server=AURO-RA4"
    con = New SqlConnection(s tr)
    Try
    con.Open()
    Catch
    End Try
    str1 = "Insert into theater values('" & TextBox1.Text & "','" & TextBox2.Text & "')"
    cmd = New SqlCommand(str1 , con)
    cmd.ExecuteNonQ uery()
    con.Close()
    Response.Write( "Inserted")
    dgstr = "select * from theater"
    dgcmd = New SqlCommand(dgst r, con)
    da = New SqlDataAdapter( dgstr, con)
    ds = New DataSet()
    da.Fill(ds)
    GridView1.DataS ource = ds
    GridView1.DataB ind()
    End Sub
    [/code]
    Here the records are getting inserted but the GridView1 is not getting visible while running. There is also no error
  • Fuhrer
    New Member
    • Dec 2006
    • 30

    #2
    Originally posted by sweatha
    Hi Friends

    I have designed a form with 2 label boxes, 2 text boxes & 1 command button. If I click the command button then, the value entered in the text boxes should be inserted in the db & at the same time it should display in the grid view. The platform is ASP.NET with SQL SERVER 2000.
    ...

    Here the records are getting inserted but the GridView1 is not getting visible while running. There is also no error

    Hi there,
    i THINK u should put this piece of your code before Response.Write( "Inserted") :
    [code=cpp]
    (
    dgstr = "select * from theater"
    dgcmd = New SqlCommand(dgst r, con)
    da = New SqlDataAdapter( dgstr, con)
    ds = New DataSet()
    da.Fill(ds)
    GridView1.DataS ource = ds
    GridView1.DataB ind()

    Response.Write( "Inserted")
    )[/code]
    Last edited by Frinavale; Mar 22 '08, 09:52 PM. Reason: Added [code] tags

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by sweatha
      Hi Friends

      I have designed a form with 2 label boxes, 2 text boxes & 1 command button. If I click the command button then, the value entered in the text boxes should be inserted in the db & at the same time it should display in the grid view. The platform is ASP.NET with SQL SERVER 2000.

      The coding I have given is
      [code=vbnet]

      Imports System.Data
      Imports System.Data.Sql Client
      '------------------------------------------------------------------------------------
      Dim con As SqlConnection
      Dim cmd As SqlCommand
      Dim dgcmd As SqlCommand
      Dim str, str1 As String
      Dim dgstr As String
      Dim da As SqlDataAdapter
      Dim ds As DataSet
      '------------------------------------------------------------------------------------
      Protected Sub Button4_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button4.Click
      str = "user id=sa;password= ;data source=AURO-RA4;initial catalog=suganya ;server=AURO-RA4"
      con = New SqlConnection(s tr)
      Try
      con.Open()
      Catch
      End Try
      str1 = "Insert into theater values('" & TextBox1.Text & "','" & TextBox2.Text & "')"
      cmd = New SqlCommand(str1 , con)
      cmd.ExecuteNonQ uery()
      con.Close()
      Response.Write( "Inserted")
      dgstr = "select * from theater"
      dgcmd = New SqlCommand(dgst r, con)
      da = New SqlDataAdapter( dgstr, con)
      ds = New DataSet()
      da.Fill(ds)
      GridView1.DataS ource = ds
      GridView1.DataB ind()
      End Sub
      [/code]
      Here the records are getting inserted but the GridView1 is not getting visible while running. There is also no error
      Are you sure that "select * from theater" returns anything?
      This type of thing typically happens when there is nothing for the GridView to display...by this I mean that the GridView's data source has nothing in it.

      -Frinny

      Comment

      • malav123
        New Member
        • Feb 2008
        • 217

        #4
        You can check the code by Putting break points Otherwise in .aspx page use the property "EmptyDataT ext" in gridview tag to check whether the data comes in data table or not....

        Comment

        Working...