Insert the textbox value to database and retrive it to List Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buterfly0707
    New Member
    • Nov 2009
    • 30

    Insert the textbox value to database and retrive it to List Box

    hi evryone..
    i want to get the text box value to list box .
    And also i want this textbox value enter into the dabasex table called Area and @ th esame time insert this value to List box. here is the code wich i have use.


    Code:
    SqlConnection conn = new SqlConnection(ConnectionString);
                    String S = "Insert into Area values ('" + textBox1.Text.ToString().Trim() + "')";
                    SqlCommand command = new SqlCommand(S);
                    SqlDataAdapter da = new SqlDataAdapter(S,ConnectionString);
                  // DataSet dt = new DataSet();
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                      
                   textBox1.Clear();
                    listBox1.Items.Add(dt.Rows[0].ItemArray[0].ToString());
    but here DataTable is not filling. Can any1 tell me what is the problem here.
    thank you everyone.
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Aren't you getting an error....

    you are trying to fill a datatable by passing an insert query instead of a select query....

    insert queries don't fetch values its select queries

    Comment

    • mzmishra
      Recognized Expert Contributor
      • Aug 2007
      • 390

      #3
      Why you want to use datatable to insert textbox value to the listbox.

      Comment

      • buterfly0707
        New Member
        • Nov 2009
        • 30

        #4
        i figured this out. thanks for all.

        ThatThatGuy: thanks.
        mzmishra : thanks for reply. yah no need of datatable here.

        Comment

        Working...