using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace datebase
{
class SqlOperateInfo {
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection("Server=localhost; Initial Catalog=stuinfo_table; User ID=sa; Password=123;");
SqlCommand Scommand = new SqlCommand();
Scommand.Connection = conn;
Scommand.CommandType = "select * from stuinfo_table"; conn.Open(); SqlDataReader sdr;
sdr = Scommand.ExecuteNonQuery(); while(sdr.Read())
{
这的内容不知如何去写????? 我的表结构是四个字段分别为name
age brithday sex
}
}
}
}
谢谢大家了..........
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace datebase
{
class SqlOperateInfo {
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection("Server=localhost; Initial Catalog=stuinfo_table; User ID=sa; Password=123;");
SqlCommand Scommand = new SqlCommand();
Scommand.Connection = conn;
Scommand.CommandType = "select * from stuinfo_table"; conn.Open(); SqlDataReader sdr;
sdr = Scommand.ExecuteNonQuery(); while(sdr.Read())
{
这的内容不知如何去写????? 我的表结构是四个字段分别为name
age brithday sex
}
}
}
}
谢谢大家了..........
while (sdr.Read())
{
System.Console.Write(sdr["name"]);
System.Console.Write(sdr["age"]);
System.Console.Write(sdr["brithday"]);
System.Console.Write(sdr["sex"]);
System.Console.WriteLine();
}这样就可以了
我是小菜鸟! 说的不好清见谅, 希望能够帮到你!
SqlCommand Scommand = new SqlCommand();
Scommand.Connection = conn;
Scommand.CommandText = "select * from stuinfo_table"; conn.Open(); SqlDataReader sdr = Scommand.ExecuteReader(); while(sdr.Read())
{
System.Console.Write(sdr["name"]);
System.Console.Write(sdr["age"]);
System.Console.Write(sdr["brithday"]);
System.Console.Write(sdr["sex"]);
System.Console.WriteLine();
}
SqlCommand Scommand = new SqlCommand();
Scommand.Connection=conn;
Scommand.CommandType=CommandType.Text;
Scommand.CommandText = "select * from stuinfo_table"; conn.Open(); SqlDataReader sdr;
sdr = Scommand.ExecuteReader(); while(sdr.Read())
{
Console.WriteLine(sdr["name"].ToString().Trim());
Console.WriteLine(sdr["age"].ToString().Trim());
Console.WriteLine(sdr["birthday"].ToString().Trim());
Console.WriteLine(sdr["sex"].ToString().Trim());
}
conn.Close();
SqlCommand Scommand = new SqlCommand();
Scommand.Connection=conn;
Scommand.CommandType=CommandType.Text;
Scommand.CommandText = "select * from stuinfo_table"; conn.Open(); SqlDataReader sdr;
sdr = Scommand.ExecuteReader(CommandBehavior.CloseConnection); while(sdr.Read())
{
Console.WriteLine(sdr["name"].ToString().Trim());
Console.WriteLine(sdr["age"].ToString().Trim());
Console.WriteLine(sdr["birthday"].ToString().Trim());
Console.WriteLine(sdr["sex"].ToString().Trim());
}
conn.Close();