Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: .NET3.5 C#
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
Posted 27-Apr-11 10:47am
Edited 27-Apr-11 10:48am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^]
Member 7685573 at 27-Apr-11 16:00pm
it is not getting what i want
Nishant Sivakumar at 27-Apr-11 16:06pm
See my updated answer.
walterhevedeich at 27-Apr-11 21:12pm
5 for the informative links, and for the patience to the OP. :)
Nishant Sivakumar at 28-Apr-11 8:07am
Thanks :-)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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);
            ktra = 0;
        catch (Exception )
            ktra = 1;           

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web03 | 2.8.150326.1 | Last Updated 27 Apr 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100