我如何向数据库中插入和删除数据(表)

问题描述:



我想知道如何从表中插入和删除数据并认为你

我已使用此代码:

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();



但是此代码不会更改Table



but this code don''t change data of Table

Hi,
的数据
我认为没有.表Etudiant中的列数大于2,并且仅在2列中插入值,因此您应指定要插入的列名,第二次尝试在类似===>的值中使用''''

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 ===>

Insert into Etudient(col1,col2) value('','');


hi bachir,

以下链接中有一个很好的代码示例:
http://msdn.microsoft.com/en-us/library/ms233812 (v = vs.80).aspx [
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 ) :-)


查看^ ].关于SQL语句如何工作的漂亮而简单的示例.
Check out SQL Tutorial[^]. Nice and simple examples on how SQL statements works.