Results 1 to 6 of 6

Thread: Is it possible to insert value of TextBox into Sql database using C sharp?

  1. #1
    Join Date
    Dec 2009
    Posts
    41

    Is it possible to insert value of TextBox into Sql database using C sharp?

    Hi Friends,

    Is it possible to insert value of TextBox into Sql database using C sharp ? I am trying to code the c sharp program to insert value of TextBox into Sql database, but I am not yet successful in it.
    I want to know your suggestion over this, please don't hesitate to suggest. I am waiting for your reply.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Is it possible to insert value of TextBox into Sql database using C sharp?

    Hi,

    Use following statement in your program to insert the textbox value and execute that program.
    sqlcommand SQcmd =
    new sqlcommand ("INSERT INTO TABdemo values (@textboxName1.text, @textboxName2.text)", Connectionstring);
    I hope it will definitely help you.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Is it possible to insert value of TextBox into Sql database using C sharp?

    Hello Friend,

    Yes it is possible to insert value of TextBox into Sql database using C sharp. I have tried this try of program many times. But code for this program is quit complicated to understand, See below:
    SqlCommand CmdSqlStr = new SqlCommand("insert into Customers (FirstNm,SurNm,Addr,,Pstcode,PhoneNum)
    Values (@FirstNm,@SurNm,@Addr,@Pstcode,@PhoneNum)", conn);

    conn.Open();

    CmdSql.Parameters.AddWithValue("@PhoneNum", PhoneNum);
    CmdSql.Parameters.AddWithValue("@Pstcode", Pstcode);
    CmdSql.Parameters.AddWithValue("@FirstNm", FirstNm);
    CmdSql.Parameters.AddWithValue("@SurNm", SurNm);
    CmdSql.Parameters.AddWithValue("@Addr", Addre);

    CmdSql.ExecuteNonQuery();

    conn.close();

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Is it possible to insert value of TextBox into Sql database using C sharp?

    Hi,

    I think you need to use the "insert" command of SQL in your C sharp program. First define the connection string for SQL database connection. Then you need to assign the "insert" command to the defined connection string. Following is the syntax and example for the same:

    Syntax:
    Insert into tableName(columnName, columnName,columName) values (ColumnValues,ColumnValues,ColumnValues)

    Example:
    Insert into emply (EmpName, empl_id, dsigntion) values ('"+txtbox1.text+"',"+txtbox2.text+",'"+textbox3.text +"');

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Is it possible to insert value of TextBox into Sql database using C sharp?

    Example of inserting textbox value into the sql:
    void Buttn1_Click(EventArgs e, object sender )
    {

    SqlConnection myCon = new SqlConnection();

    myCon.ConnectionString = “Put connection string here“;

    myCon.Open();

    string strqr = “Insert into stud values (” + TextBoxOne.Text +
    “,’” + TextBoxTwo.Text + “‘,’” + TextBoxThree.Text + “‘)”;

    SqlCommand myCm = new SqlCommand (strqr, myCon);

    int numrw = myCm.ExecuteNonQuery();

    myCon.Close();

    }

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: Is it possible to insert value of TextBox into Sql database using C sharp?

    I have used below sqlcommand statement in my c sharp program for sql database connection. Copy this sqlcommand statement and replace the the values of "txtbx1" and "txtbx2" with your defined names for text boxes:
    sqlcommand cmmd =
    new sqlcommand("insert into addressdemo values
    ('"+ txtbx1.text +"', "+ txtbx2.text +")",
    connectionstring);

Similar Threads

  1. insert into select statement for database
    By Aidan 12 in forum Software Development
    Replies: 5
    Last Post: 09-03-2010, 10:08 PM
  2. Insert DataGridview into database
    By Neil'o in forum Software Development
    Replies: 3
    Last Post: 24-09-2009, 11:28 AM
  3. How do I create a textbox in vb that lets you insert tabs?
    By Chandrakant81 in forum Software Development
    Replies: 3
    Last Post: 26-02-2009, 09:59 PM
  4. How can I bind textbox with column in SQL database?
    By SushmitaP in forum Software Development
    Replies: 3
    Last Post: 19-02-2009, 10:57 PM
  5. Insert image in access database from vb 6.0
    By Vireshh in forum Software Development
    Replies: 2
    Last Post: 22-01-2009, 09:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,580,162.79349 seconds with 16 queries