473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can I transmit data from Database to List<>?

meomap0z1
Firstly, I connect Database and I wanna transmit data to my public List<Product> GetProductList. Can I do this?
Expand|Select|Wrap|Line Numbers
  1. public DataTable GetBooks()
  2.         {
  3.             string SQL = "Select * From Products";
  4.             SqlConnection cnn = new SqlConnection(strConnection);
  5.             SqlCommand cmd = new SqlCommand(SQL, cnn);
  6.             SqlDataAdapter da = new SqlDataAdapter(cmd);
  7.             DataTable dtProduct = new DataTable();
  8.             try
  9.             {
  10.                 if (cnn.State == ConnectionState.Closed)
  11.                 {
  12.                     cnn.Open();
  13.                 }
  14.                 da.Fill(dtProduct);
  15.             }
  16.             catch (SqlException se)
  17.             {
  18.                 throw new Exception(se.Message);
  19.             }
  20.             finally
  21.             {
  22.                 cnn.Close();
  23.  
  24.             }
  25.             return dtProduct;
  26.         }
  27.  
Have a nice day, guys.
Mar 8 '20 #1

✓ answered by AjayGohil

Hi meomap0z1,

Yes,you can pass data from database to List.

Firstly create a list and fetch data from row of dataTable and store it through Add command which store data in List.

Add Following code to your program.

Expand|Select|Wrap|Line Numbers
  1. List<Product> GetProductList =new List<Product>();
  2.     foreach (GetProductList  p in dtProduct.Rows)
  3.     {
  4.             GetProductList .Add(p);
  5.     }
and you can also use

1 3099
AjayGohil
83 64KB
Hi meomap0z1,

Yes,you can pass data from database to List.

Firstly create a list and fetch data from row of dataTable and store it through Add command which store data in List.

Add Following code to your program.

Expand|Select|Wrap|Line Numbers
  1. List<Product> GetProductList =new List<Product>();
  2.     foreach (GetProductList  p in dtProduct.Rows)
  3.     {
  4.             GetProductList .Add(p);
  5.     }
and you can also use
Mar 12 '20 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Liu Ju | last post by:
Dear members: I need to write a program in Visual C++ platform that trasmit data through the COM port. The task would be as follows: Whenever the peripheral device sents 1 byte to the computer...
2
by: Jake_adl | last post by:
Is there any way to create a Microsoft.Practices.EnterpriseLibrary.Data.Database object without reading from a configuration file? I am writing a utility that manages databases in SQL Server....
3
by: Rasha | last post by:
Hi, What is the right way for transmitting data on the serial port of a PC using VB.NET (under XP) ? I used to use the ActiveX MSComm under VB6, which becomes obsolete and needs a...
3
by: andrewtayloruk | last post by:
I'm a newbie when it come to things php and i'm having a bit of trouble. I'm trying to insert data from an html form into a mysql database and can't get it to work. Just a few bits about my...
0
by: dyc | last post by:
I'm quite new to use the microsoft visuol studio....all the things I need to learn by myself...so hope can get some help from this forum.. My problem is how do I transmit data using VB language...
8
sumaiya
by: sumaiya | last post by:
I have interactive flash website intelution.com It is getting data from a database using PHP file system print "&photo$i=http://www.intelution.com/$photo&prod$i=$prod&"; The thing is the...
0
parshupooja
by: parshupooja | last post by:
Hey All, I am trying to create utility to check data inconsistency in ASP.net 2.0 C# means I want to compare two databases in two different sources i.e MS Access and SQL Server. I want to...
2
by: bany39 | last post by:
hi here server and client code , but there is two problem 1=speed of data transmit , is so important for me , because i want controling the robot movement with this program , but every time i...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.