????2. C# ?????????
????C# ???????????·???
????1???????????????????????? 2???????????????SQL?????? 3??????SQL????????в??????????
??????????SQL Server??
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//connection-string(Local Server:127.0.0.1) & SQL-string define
string conString = "Server=(local); database=test; uid=sa; password=123456";
string sqlString = "select * from Monitor;";
//create a connection
SqlConnection con = new SqlConnection(conString);
con.Open();
//create a SQL command within connection?? use SqlDataReader(light-level) to read retrieved data
SqlCommand cmd = new SqlCommand(sqlString?? con);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
Console.WriteLine("{0} {1} {2} {3}"?? sdr["ID"]??sdr["RecordTime"]??sdr["VideoView"]??sdr["Fluency"]);
con.Close();
cmd.Dispose();
//create a SQL command within connection?? use SqlDataAdapter to read retrieved data
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(sqlString?? con);
DataSet dst = new DataSet();
sda.Fill(dst?? "Monitor");
foreach (DataRow row in dst.Tables["Monitor"].Rows)
Console.WriteLine(row["ID"] + " " + row["RecordTime"] + " " + row["VideoView"] + " " + row["Fluency"]);
con.Close();
Console.ReadKey();
}
}
}
?????????????????Server???????server??ip?????database?????????????????????SqlDataReader??SqlDataAdapter???????????????
???????????????????????????????????1?????????????????server???2????????server?????????????????????????sql????????table???