试简述使用Command对象进行数据库操作的基本设定方法和过程步骤

谢谢帮助!~
2024-11-23 00:00:27
推荐回答(1个)
回答(1):

1. Command介绍�0�1 Dispose()�0�1 CommandText�0�1 构造函数()SqlConnection conn = new SqlConnection(); conn.ConnectionString = "server=KEVIN-LI;database=ADONET;uid=admin;pwd=123456"; //打开连接薯纳 conn.Open(); //执判手蠢行命令 SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; string sql = "select * from 销售记录掘陪表"; cmd.CommandText = sql; SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { dr.Read(); dr.Read(); MessageBox.Show(dr.GetString(1)); } conn.Close(); conn.Dispose();