Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

It's pretty easy:
C#
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();
        }
    }
 
Share this answer
 
Comments
bbirajdar 19-Jul-12 11:07am    
I hope he understands where to use this code
I will help you by writing the code,

C#
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");
       }
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900