Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
hi i have a win form in C#.net
in this form there are 3 textbox...

i want to insert informacion from textbox to my sql express 2005 DB? I am using WiFi to comunicate with dB on another computer... my communication with database is establish perfectly...

how do I insert informacion in DB? I need example or code for that problem...

thank you
Posted
Comments
Marc A. Brown 27-May-11 12:15pm    
Are you having problems getting something to work or are you unsure of what to do?
FeniksReborn 27-May-11 12:44pm    
I am unsure of what to do :( My conection with the DB is always open, it only close after exit button(exit aplication)
I writte this in button insert_DB_city:
conn="MY IP adres and path to DB on another computer";
SqlConnection connection1 = new SqlConnection(conn); // this is the problem

SqlCommand insertCommand = new SqlCommand(
"INSERT into Wood (city) values ("'+txtwood.text+")",
connection1);

connection1.Open(); // and this (but i know why, because conection is always open :) don't need that
insertCommand.ExecuteNonQuery();
connection1.Close();

My DB already have row city, and there is about 1000 articals in DB. I just need to insert information in colum city :(
FeniksReborn 27-May-11 13:09pm    
I think i need to use SQL UPDATE Statement for my problem....
Rob Branaghan 29-May-11 3:53am    
If you want to UPDATE a record that already exists, use UPDATE. If you want to INSERT a new record use INSERT. If your table has "NON NULL" fields you will have to populate those as well.

 
Share this answer
 
Comments
Kim Togo 27-May-11 12:40pm    
Good links, my 5. OP has the answer her.
Rob Branaghan 29-May-11 3:54am    
Thank you :)
Monjurul Habib 27-May-11 15:48pm    
my 5 for the links.
Rob Branaghan 29-May-11 3:54am    
Thank you :)
If you are looking at information on how to insert records, you could start from here[^].
 
Share this answer
 
Comments
Monjurul Habib 27-May-11 15:47pm    
cool link.my 5.
Abhinav S 28-May-11 0:39am    
Thank you.
Seems like you have forgotten a (') in your query.

SqlCommand insertCommand = new SqlCommand( "INSERT into Wood (city) values ('"+txtwood.text+")", connection1); 


try this;

SqlCommand insertCommand = new SqlCommand( "INSERT into Wood (city) values ('"+txtwood.text+"')", connection1);
 
Share this answer
 
v2

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