In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how DataTable creates rows and columns and realizes DataReader reading. I hope you will get something after reading this article. Let's discuss it together.
Public DataTable read ()
{
String str = "select id,UserName,UserPwd from Users"; / / SQL statement
SqlCommand cmd = new SqlCommand (str, conn)
DataTable table = new DataTable (); / / create the table
DataColumn dc=null;// definition
Dc=table.Columns.Add ("number", Type.GetType ("System.Int32")); / / create columns, column names and types
Dc.AutoIncrement = true; / / Auto column
Dc.AutoIncrementSeed = 1; / / starting from 1
Dc.AutoIncrementStep = 1 / step size is 1
Dc=table.Columns.Add ("user name", Type.GetType ("System.String")); / / create the second column
Dc=table.Columns.Add ("password", Type.GetType ("System.String")); / / create the third column
DataRow newRow
Conn.Open ()
SqlDataReader reader = cmd.ExecuteReader ()
While (reader.Read ())
{
NewRow = table.NewRow (); / / create a new line
NewRow ["number"] = reader ["id"]; / / assign a value to a row
NewRow ["user name"] = reader ["username"] .ToString ()
NewRow ["password"] = reader ["userpwd"] .ToString ()
Table.Rows.Add (newRow); / / add rows to the table
}
Return table
}
After reading this article, I believe you have some understanding of "how to create rows and columns and achieve DataReader reading in DataTable". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 209
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.