标签:ase into 连接数 string 通过 new val str 数据
ADO.NET:数据库访问技术(通过程序来连接访问数据库)
连接数据库增删改:
string cs = "server=.;user=sa;pwd=123;database=date0908";
SqlConnection con = new SqlConnection(cs);
SqlCommand com = con.CreateCommand();
//com.CommandText = "insert into student values(‘木婉清‘,‘0‘,‘2006-06-06‘)";
//com.CommandText = "delete from student where ids=12";
com.CommandText = "update student set name=‘阿碧‘ where name=‘虚竹‘";
con.Open();
int a = com.ExecuteNonQuery();
con.Close();
if (a > 0) Console.WriteLine("成功");
else Console.WriteLine("失败"); --只能有一句执行语句
连接数据库查:
string cs = "server=.;user=sa;pwd=123;database=date0908";
SqlConnection con = new SqlConnection(cs);
SqlCommand com = con.CreateCommand();
com.CommandText = "select * from student";
con.Open();
SqlDataReader dr = com.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Console.Write(dr["name"]);
Console.Write("——");
Console.Write(dr["sex"]);
Console.Write("——");
Console.Write(dr["birthday"]);
Console.Write("——");
Console.WriteLine();
}
}
con.Close();
标签:ase into 连接数 string 通过 new val str 数据
原文地址:http://www.cnblogs.com/m110/p/7825548.html