Click here to Skip to main content
14,665,547 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,

I am a newbie to this site, so I dont know to use this, how to reply and all stuffs.
I am doing a project and I want code in C# for saving a given input from text boxex into a database from a windows form.
Can any one give a simple example that I run at my local.
I will modify the code as per my requirement.

Please help me.

Thanks in advance.
Posted
v2
Comments
[no name] 19-Jul-12 9:55am
   
Welcome to the site. No one here is going to write a program for you. That is up to you.

Rate this:
Please Sign up or sign in to vote.

Solution 1

It's pretty easy:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }
   
Comments
bbirajdar 19-Jul-12 11:07am
   
I hope he understands where to use this code
Rate this:
Please Sign up or sign in to vote.

Solution 3

I will help you by writing the code,

private void button1_Click(object sender, EventArgs e)
       {
           con.Open();
           cmd = new SqlCommand("Insert into SalesDetails Values('" + textBox1.Text + "','" + dateTimePicker1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "')", con);
           cmd.ExecuteNonQuery();
           con.Close();
           MessageBox.Show("Added");
       }
   
v2
Comments
[no name] 19-Jul-12 10:37am
   
And open yourself to SQL injection attacks.
bbirajdar 19-Jul-12 11:06am
   
I agree... with Wes
shaikh-adil 5-Aug-12 4:54am
   
bro...
i am doing a project on shop management system. so i needed it.
i am dealing with database cz i need to store the customer name. i want a project to get some ideas on managing data.does anbody knows a readymade prject
i am using visual studio 2010 as m university told me.
help me guyz

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100