SqlCommand-Asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeenajos
    New Member
    • Oct 2007
    • 71

    SqlCommand-Asp.net

    Hi all,
    I had used a sqlquery in sqlcommand for retrieving the tablename that is entered by the user thru a textbox.
    Using that tablename.It should display the records in that tablename.
    But one error is coming.
    Code is as

    cmd = New SqlCommand("sel ect mobileno from '" & file & "'", con)
    d = cmd.ExecuteRead er()

    File is the tablename that is entered by the user.
    The controls goes to the catch statement after executereader is called.
    Error is Incorrect syntax near file

    Does anyone knows any solution. Can we give like this.
    And also How to download the record from the given table in access or notepad

    Thank u in Advance.
    Regards
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Remove the single quotes from around the file variable..

    Comment

    • jeenajos
      New Member
      • Oct 2007
      • 71

      #3
      Thanks. It worked.
      Im displaying the numbers in a listbox. Can i download it into a notepad or an access database?

      While (d.Read())
      ListBox1.Items. Add(d.Item(0))
      End While

      Is this correct?
      Response.Conten tType = "text/html"
      Response.AddHea der("content-disposition", "filename=" & file)
      Response.Flush( )

      Thanks
      Regards

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by jeenajos
        Thanks. It worked.
        Im displaying the numbers in a listbox. Can i download it into a notepad or an access database?

        While (d.Read())
        ListBox1.Items. Add(d.Item(0))
        End While

        Is this correct?
        Response.Conten tType = "text/html"
        Response.AddHea der("content-disposition", "filename=" & file)
        Response.Flush( )

        Thanks
        Regards
        You can use TextWriter to write to a text file. For storing to the database, read about how to use ADO.NET.

        Comment

        Working...