Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with insert
Message
De
24/10/2006 11:06:53
 
 
À
24/10/2006 10:33:52
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01164088
Message ID:
01164096
Vues:
9
>How I make to insert dataset in sqlserver 2005 database with vs 2003.

Read in Help about updating (or inserting) with OleDB (ADO.NET Command object).

Here's one way (example):
public int AddOrders(string sOrderID, string sProductID, double nQuantity, double nUnitPrice)
{
  string sConn=System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ToString();
  string sSQL = "INSERT INTO [Order Details] "+
    "(OrderID, ProductID, Quantity, UnitPrice) "+
    "VALUES @OrderID, @ProductID, @Quantity, @UnitPrice)";
  SqlConnection oConn = new SqlConnection(sConn);
  SqlCommand oCmd = new SqlCommand(sSQL, oConn);
  oCmd.CommandText = sSQL;
  oCmd.CommandType = CommandType.StoredProcedure;
  oCmd.Parameters.Add("@OrderID", SqlDbType.Int);
  oCmd.Parameters.Add("@ProductID", SqlDbType.Int);
  oCmd.Parameters.Add("@Quantity", SqlDbType.Double);
  oCmd.Parameters.Add("@UnitPrice", SqlDbType.Double);
  oCmd.Parameters[0].Value = sOrderID;
  oCmd.Parameters[1].Value = sProductID;
  oCmd.Parameters[2].Value = nQuantity;
  oCmd.Parameters[3].Value = nUnitPrice;
  oCmd.Connection = oConn;
  oConn.Open();
  int nRowsInserted = oCmd.ExecuteNonQuery();
  oConn.Close();
  oCmd = null;
  return nRowsInserted;
}
Note: It reads the connection string from Web.Config


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform