Home > database > C # how random data from SQL server database to array?
C # how random data from SQL server database to array?
Time:09-16
For c # to do course design, a blank, the first post, shivering
CodePudding user response:
CodePudding user response:
I write so, said an error index beyond array bounds, strives for the great god
CodePudding user response:
CodePudding user response:
Give a similar example, you can change according to the:
using System; using System.Collections.Generic; using System.Linq; using System.Text; Using System. The Data. SqlClient. using System.Data; Using System.Data.Com mon;
The namespace ConsoleApplication12 { Class Program { The static void Main (string [] args) { String connString=@ "Data Source=. \ sqlserver2005; Initial Catalog=master; Integrated Security=True "; String SQL=@ "SELECT TOP 3 number FROM [master] dbo. Spt_values AS sv WHERE sv. [type]='P' ORDER BY NEWID ()". DataTable dt=new DataTable(); Try { Using (SqlConnection conn=new SqlConnection (connString)) { Conn. The Open (); SqlCommand CMD=new SqlCommand (SQL, conn); SqlDataAdapter adapter=new SqlDataAdapter (CMD); Adapter. The Fill (dt); Console. WriteLine (" implementation success, "); }