1 Replies - 2928 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

Hello,

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()
        {
            InitializeComponent();
        }

        private void telefoniBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.telefoniBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.telefoniDataSet);

        }

        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.
            this.telefoniTableAdapter.Fill(this.telefoniDataSet.Telefoni);

        }

        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);
                conn.Open();

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

                CmdSql.ExecuteNonQuery();
                conn.Close();
            }
        }
    }
}







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: 5476
  • View blog
  • Posts: 11,762
  • 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
Spoiler



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1