Click here to Skip to main content
Rate this: bad
good
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
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
[Edit]
~~~~~~~~~~~
 
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[^]
  Permalink  
v3
Comments
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
good
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);
        try
        {
            sqlconn.Open();
            sqlcmd.ExecuteNonQuery();
            sqlconn.Close();
            ktra = 0;
        }
        catch (Exception )
        {
            sqlconn.Close();
            ktra = 1;           
        }
    }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 406
1 /\jmot 180
2 Suraj Sahoo | Coding Passion 170
3 Afzaal Ahmad Zeeshan 159
4 BillWoodruff 154
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 27 Apr 2011
Copyright © CodeProject, 1999-2014
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