查询在sql中插入数据 [英] query for inserting data in sql

查看:135
本文介绍了查询在sql中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在sql数据库中插入数据,例如插入表名(name)values(''mahesh'')中,其中id = 102;如何在c#.net

I want to insert data in sql data base eg.insert into tablename(name) values(''mahesh'') where id=102; how to fire such query in c# .net

推荐答案

中触发此类查询,请参见

~~~~~~~~~~~

这是对您的评论的回应.看到这篇文章:

OLE DB-第一步 [ http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson03.aspx [ ^ ]
See http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.executenonquery.aspx[^]

This is a very basic a question. If you google for "C# database insert" or "C# ole db" you''ll get lots of hits.


~~~~~~~~~~~

This is in response to your comment. See this article:

OLE DB - First steps[^]

I wrote the first version almost 10 years ago and the code syntax uses the now obsolete MC++ syntax, but it should give you some ideas.

Also, see:
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson03.aspx[^]


希望我的代码对您有所帮助.
请根据您的要求进行修改.

I hope that my code will helpful with you.
Please modify it to your requirement.

#region  Hàm thêm Product vào chi tiết order
    public static void InsertCTOrder(int OrderID, int ProID, int Quantity, string UnitPrice,int ktra,SqlConnection sqlconn)
    {
        string strInSert = "INSERT INTO OderDetail VALUES (@OrderID, @ProID, @Quantity, @UnitPrice)";
        SqlCommand sqlcmd = new SqlCommand(strInSert, sqlconn);
        sqlcmd.Parameters.AddWithValue("@OrderID", OrderID);
        sqlcmd.Parameters.AddWithValue("@ProID", ProID);
        sqlcmd.Parameters.AddWithValue("@Quantity", Quantity);
        sqlcmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
        try
        {
            sqlconn.Open();
            sqlcmd.ExecuteNonQuery();
            sqlconn.Close();
            ktra = 0;
        }
        catch (Exception )
        {
            sqlconn.Close();
            ktra = 1;           
        }
    }


这篇关于查询在sql中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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