1 Replies - 3729 Views - Last Post: 11 June 2012 - 08:58 AM Rate Topic: -----

#1 Strezoski777  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 23-April 12

How to transfer text from text box to table in SQL database?

Posted 11 June 2012 - 08:43 AM


I'm developing an Windows Forms application that has a SQL database with a table in it. There are also text boxes in witch I'm typing in information.

Im wondering how to copy all the information from the text boxes to the table and update the view on a Button click?

Here is my code:

namespace Alfa_Sound
    public partial class Form1 : Form
        public Form1()

        private void telefoniBindingNavigatorSaveItem_Click(object sender, EventArgs e)


        private void Form1_Load(object sender, EventArgs e)
            // TODO: This line of code loads data into the 'telefoniDataSet.Telefoni' table. You can move, or remove it, as needed.


        private void button1_Click(object sender, EventArgs e)
            using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS; AttachDbFilename=C:\AlfaSoundApp\Alfa Sound\Alfa Sound\Telefoni.mdf;Integrated Security=True;User Instance=True"))
                SqlCommand CmdSql = new SqlCommand("INSERT INTO [Telefoni]  (Ime, Prezime, Kontakt) VALUES ( @Ime, @Prezime, @Kontakt)", conn);

                CmdSql.Parameters.AddWithValue("@Ime", tb_Ime.Text);
                CmdSql.Parameters.AddWithValue("@Prezime", tb_Prezime.Text);
                CmdSql.Parameters.AddWithValue("@Kontakt", tb_Telefon.Text);


Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: How to transfer text from text box to table in SQL database?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5871
  • View blog
  • Posts: 12,788
  • Joined: 02-June 10

Re: How to transfer text from text box to table in SQL database?

Posted 11 June 2012 - 08:58 AM

See FAQ # 22. (Click the SHOW button below)

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2

FAQ (Frequently Asked Questions - Updated May 2012

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1