Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > C# 2012/5.0 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2012/5.0 General Discussion Discussions about the C# 2012 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2012/5.0 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 20th, 2014, 09:30 PM
Authorized User
Points: 132, Level: 2
Points: 132, Level: 2 Points: 132, Level: 2 Points: 132, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 25
Thanks: 3
Thanked 0 Times in 0 Posts
Question How do you insert a record into an SQL database using LINQ

Hi,

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?

Thanks,
Truck35
Reply With Quote
  #2 (permalink)  
Old June 21st, 2014, 02:16 AM
Wrox Author
Points: 1,154, Level: 13
Points: 1,154, Level: 13 Points: 1,154, Level: 13 Points: 1,154, Level: 13
Activity: 25%
Activity: 25% Activity: 25% Activity: 25%
 
Join Date: Sep 2010
Location: Austria
Posts: 172
Thanks: 2
Thanked 53 Times in 53 Posts
Default

The LINQ syntax is a query syntax. Use Entity Framework or other technologies for inserting records.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
Reply With Quote
  #3 (permalink)  
Old June 21st, 2014, 03:41 PM
Authorized User
Points: 132, Level: 2
Points: 132, Level: 2 Points: 132, Level: 2 Points: 132, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 25
Thanks: 3
Thanked 0 Times in 0 Posts
Question 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.

Thanks,
Truck35
Reply With Quote
  #4 (permalink)  
Old April 24th, 2015, 11:30 AM
svb svb is offline
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Code:
using(OledbConnection con= new OledbConnection(connectionString)
{
   con.Open();
   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.
   }
}
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't insert a DateTime into my database with Linq to sql chobo2 ASP.NET 3.5 Basics 3 August 15th, 2009 06:55 PM
Insert data using LINQ SQL - page 471 LoriBarber BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 March 1st, 2009 08:12 PM
errro trying to insert record to sql server method ASP.NET 1.0 and 1.1 Basics 1 May 20th, 2005 09:24 PM
Insert a record into a Database ersp Classic ASP Basics 3 May 9th, 2004 09:50 PM



All times are GMT -4. The time now is 04:16 PM.


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