473,699 Members | 3,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I transmit data from Database to List<>?

meomap0z1
9 New Member
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
1 3112
AjayGohil
83 New Member
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
3937
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 through the RX pin of the COM Port, the program will send 4 bytes to the TX pin to peripheral device. do you know any source or the class in Visual C++ on the Internet that can reliably transmit data through COM port ?
2
2368
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. The utility queries SQL Server for the database names. So I don't know the names of the databases beforehand, but I will know the names and connection strings once the server has been queried. However, I have a class that I'd like to work with...
3
2733
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 certification, only available if Visual Studio 6 is installed. Thanks for any Help !!!
3
4741
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 setup, i'm running an sql server locally, i've created the database, table and fields. I think what i'm missing is something that actually runs the sql query when i hit the submit button. Also, i'm aware i haven't made the data being inserted safe, i...
0
1639
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 through the hyperterminal?what thing should i set up? I will be using the serial cable RS 232 to transmit the data.... I don't know what the set up should I set and what kind of code should I look through and apply for it... anyone can help or give...
8
2289
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 website works fine on some computers and on some computers does not load the data. i dont think its a browser issue......... wht do u thnk is causing this, any solution. is it because im not using xml???
0
1204
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 create application where I should provide two data connection strings one for Acess and one for SQL server and then I want to compare for ex: if I am comparing master DB and somebody has added table "xyz" in MS Acess master DB, then I want to generate a...
2
3792
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 want to send data with client program ,porgram send my data then disconnet and after connecting again and then send next data, and it`s so slow , how can i solve it ??? 2=how transmit data synchronous ?? Server using System; using...
0
8709
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8638
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8952
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7791
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5894
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4649
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2371
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.