C#

xiaoxiao2021-02-28  50

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; namespace ConsoleApplication1 {     class Program     {         static void Main(string[] args)         { SqlConnection sqlconnection = new SqlConnection("SERVER=.;Initial Catalog=MySchool;User ID=sa;Password=123456");//数据库连接             string sql = string.Format("SELECT * FROM Student");             sqlconnection.Open();             SqlCommand sqlcommand = new SqlCommand(sql, sqlconnection);             SqlDataAdapter da = new SqlDataAdapter(sqlcommand);             DataSet ds = new DataSet();             da.Fill(ds);             for (int i = 0; i < ds.ToString().Length; i++)             {                 Console.WriteLine(ds.Tables[0].Rows[i]["LoginId"]);//输入要打印的表中字段名                 Console.WriteLine(ds.Tables[0].Rows[i]["LoginPwd"]);//输入要打印的表中字段名             }             Console.ReadLine();                      }     } }
转载请注明原文地址: https://www.6miu.com/read-2613163.html

最新回复(0)