textbox databinding to a Sql Database.

Rate It (1)

Last post 10-22-2009 3:25 AM by gaurabchatterjee. 25 replies.

Sort Posts:

  • Re: textbox databinding to a Sql Database.

    03-23-2009, 3:46 PM
    • Member
      6 point Member
    • Jebusno2
    • Member since 03-23-2009, 7:06 PM
    • Posts 5

    I am trying to create a search page for my project which takes the values from two text boxes and uses an SQL datasource to search an SQL database and then display the results in a gridview control. The SQL statement i use is below.

    SELECT [IDno], [ItemName], [IType], [Price], [Quantity], [dateposted], Email, [phonenumber] FROM [Products] WHERE ((CONTAINS([ItemName], ?)) AND ([IType] = ?))

     It does not seem to work as when i tried to test the query it returned the error Null or empty full-text predicate and when i tried to use the query builder it returned an error message saying No value given for one or more required paramaters I do not know what to do. Please can someone help me?

  • Re: textbox databinding to a Sql Database.

    03-23-2009, 4:08 PM

    Hello There,

     

    Why you need to text boxes to search for a record? May I know? Mine is only needed one textbox, but if you need two textboxes then

     

    Select

    SELECT IDno, ItemName, IType, Price, Quantity, dateposted, phonenumber

    FROM Products WHERE ((ItemName = @ItemName) AND (IType = @IType))

    Hope it help you, if you need more helps then let me know. I will try my best to help you

     

    Thanks

     

  • Re: textbox databinding to a Sql Database.

    03-24-2009, 12:12 AM

    Please take a look at the following example that shows you how to link up your TextBox controls to the SqlDataSource and display the data in a GridView.

    http://www.csharpuniversity.com/2008/12/31/searching-database-data-using-parameters-with-the-aspnet-sqldatasource-and-gridview-controls/

  • Re: textbox databinding to a Sql Database.

    03-24-2009, 7:35 AM
    • Member
      6 point Member
    • Jebusno2
    • Member since 03-23-2009, 7:06 PM
    • Posts 5

    What i use two text boxes for is to narrow down the number of results returned by the query. Also what about the CONTAINS part?

  • Re: textbox databinding to a Sql Database.

    03-24-2009, 9:14 AM
    • Member
      6 point Member
    • Jebusno2
    • Member since 03-23-2009, 7:06 PM
    • Posts 5

     It did not work it gave an error saying must declare the scalar variable "@ItemName" what went wrong?

  • Re: textbox databinding to a Sql Database.

    06-23-2009, 10:05 AM
    • Member
      172 point Member
    • blbirajdar02
    • Member since 02-25-2008, 7:32 AM
    • Posts 68

     Use the declarative syntax to databind the textbox with the SQL field exposed as a public property or as public variable

    Balaji Birajdar
    Pune, India
  • Re: textbox databinding to a Sql Database.

    07-25-2009, 12:50 AM
    • Member
      2 point Member
    • fhd
    • Member since 07-22-2009, 7:52 AM
    • Posts 1

    Simply write you own data retrieval statement and fill the the text box ... it's very easy and totally controlled in fact

  • Re: textbox databinding to a Sql Database.

    07-25-2009, 3:18 AM
    • Member
      85 point Member
    • JawadHasan
    • Member since 01-30-2008, 10:49 AM
    • Abu Dhabi
    • Posts 88

    Hi There:

    Well, you want to perform a search. first of all you have to construct your query string well and according to data types.

     

    Dim searchCriteriaItemName As String

    Dim searchCriteriaItemType As String

    Dim searchCmd As String

    Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click""

    searchCriteriaItemName = ""

    searchCriteriaItemType = ""

     If txtItemName.Text = "" Then

    searchCriteriaItemName = "Products.ItemName '%'"

    Else

     searchCriteriaItemName = "Products.ItemName LIKE '%" & txtItemName.Text & "%'"

    End If

     If txtItemType.Text = "" Then

    searchCriteriaItemType =

    "Products.ItemType Like '%'"

     Else

     searchCriteriaItemType =

    "Products.ItemType LIKE '%" & txtItemType.Text & "%'"

     End If

     searchCmd = "SELECT [IDno], [ItemName], [IType], [Price], [Quantity], [dateposted], Email, [phonenumber] FROM [Products]"

    searchCmd = searchCmd + " WHERE " + searchCriteriaItemName + " AND " + searchCriteriaItempType

    Me.SqlDataSource2.SelectCommand = searchCmd

    Me.SqlDataSource2.DataBind()

    End Sub

     So, This is the logic, you can modify the code according to your requirements.

    Jawad Hasan
    http://www.muzaffargarh.biz
  • Re: textbox databinding to a Sql Database.

    08-03-2009, 6:37 AM
    • Member
      23 point Member
    • drahmedgalal
    • Member since 07-06-2008, 4:35 PM
    • egypt
    • Posts 14

    i don't know why you write all this code,

    simply 

    drag sqldatasource control on the page

    configure it with the sql statement you need

    drag  formview to the page and choose it's data source proberity to the sqldata source you added

    customize the formview to your needs

    and it is done without a line of code 

  • Re: textbox databinding to a Sql Database.

    10-21-2009, 4:33 PM
    • Member
      2 point Member
    • alfred39
    • Member since 10-21-2009, 8:19 PM
    • Posts 1

    Hi  guys!

    I have a laptop hp with vista home premium installed. Whenever I install Visual Web Developer 2008 with SQL server 2008 and I need to add a new item on my web site it gives me an error " you need to install SQL 2005 server in order to work correctly.  Second question is: How can I change my SQL string connection when I need to transfer my web site to the hosting server. I have tried meny times and it doesn't work. Any examples would be very helpfull. lastly How can I insert a text from the textbox to the database.

    Thank you


  • Re: textbox databinding to a Sql Database.

    10-22-2009, 3:25 AM

    To bind a text box to sql data just

    fetch the data by your custom method . and bind the value like  the following

    DataTable mTable = null;

    mTable =//Populate the Datatable

    foreach (DataRow mRow in mTable.Rows)
    {

    TextBox1.Text =mRow["Field name of database"].ToString();

    }

    Gaurab Chatterjee
Page 2 of 2 (26 items) < Previous 1 2