p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# 2012/5.0 General Discussion (http://p2p.wrox.com/forumdisplay.php?f=714)
-   -   How do you insert a record into an SQL database using LINQ (http://p2p.wrox.com/showthread.php?t=93126)

Truck35 June 20th, 2014 08:30 PM

How do you insert a record into an SQL database using LINQ

I looked all over but, I can't find any resources that tells me how to insert a record into a SQL Database using LINQ syntax. Could someone please help me?


ChristianNagel June 21st, 2014 01:16 AM

The LINQ syntax is a query syntax. Use Entity Framework or other technologies for inserting records.

Truck35 June 21st, 2014 02:41 PM

Need Code to insert record into SQL Database
What is the syntax used to extract data from a relational database and display it into a text box using c#. I already know how to establish a connection with a database but, I want to take the data and display it into a textbox. How do you do that?

If anyone could help me, I would appreciate it.


svb April 24th, 2015 10:30 AM

Depending on your database, you may want to change the type of connection. The example below is to insert into an access database and retrieve value from the same database and display into a text box. You may want to change it to SqlConnection or SqlCommand if you are using SQL server.


using(OledbConnection con= new OledbConnection(connectionString)
  string sql="Enter your sql query here";
  using(OledbCommand cmd= new OledbCommand(sql, con);
// Use only one of the below in one using block.
      cmd.ExecuteNonQuery(); // For inserting into DB.
      txtbox1.Text= Convert.ToString(cmd.ExecuteScalar()); // For returning value to text box.

All times are GMT -4. The time now is 11:54 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.