Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guts,

i want to know how to insert anf delete data from tables and think you

i have use this code :

SqlConnection sc = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Ecole.mdf;Integrated Security=True;User Instance=True");
            SqlDataAdapter da = new SqlDataAdapter();

            da.InsertCommand = new SqlCommand("INSERT INTO Etudiant VALUES(@N,@P)", sc);
            da.InsertCommand.Parameters.Add("@N", SqlDbType.NChar).Value = nom.Text;
            da.InsertCommand.Parameters.Add("@P", SqlDbType.NChar).Value = prenom.Text;

            sc.Open();
            da.InsertCommand.ExecuteNonQuery();
            sc.Close();


but this code don't change data of Table
Posted

Hi,

I think the no. of columns in your table Etudiant are more than 2 and you are inserting values in only 2 columns,so you should specify the column names to which you want to insert,second try using '' in values like this ===>

SQL
Insert into Etudient(col1,col2) value('','');
 
Share this answer
 
v2
Comments
walterhevedeich 18-Jul-11 9:13am    
This might be what OP needs. 5ed.
hi bachir,

there is a good code example in the following link :
http://msdn.microsoft.com/en-us/library/ms233812(v=vs.80).aspx[^]

or if you using .NET 2 or higher you could use tableadapter object (also shown on the link ) :-)
 
Share this answer
 
v2
Comments
walterhevedeich 18-Jul-11 9:16am    
Good link. 5ed
Check out SQL Tutorial[^]. Nice and simple examples on how SQL statements works.
 
Share this answer
 
Comments
walterhevedeich 18-Jul-11 9:17am    
Nice link. The basics are usually the ones that are important. 5ed.
Kim Togo 18-Jul-11 10:28am    
Thanks

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