我如何向数据库中插入和删除数据(表) [英] How can i Insert,and Delete data to my database (Tables)

查看:62
本文介绍了我如何向数据库中插入和删除数据(表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

我已使用此代码:

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.


这篇关于我如何向数据库中插入和删除数据(表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆