sqlserver 做增删改查操作

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.sqlClient; using System.Configuration; namespace TellCenter { public partial class customer : Form { public customer() { InitializeComponent(); } string sqlstr = ConfigurationManager.ConnectionStrings["con"].ConnectionString; private void btnlook_Click(object sender,EventArgs e) { if (this.checkname.Checked) { using (sqlConnection sqlcnn = new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "select * from T_Clientele where ClientName=@name"; sqlcmm.Parameters.AddWithValue("@name",this.txtname.Text); GetInfo(sqlcnn,sqlcmm); } } } else if(this.checkphone.Checked) { using (sqlConnection sqlcnn=new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "select * from T_Clientele where ClientPhone=@phone"; sqlcmm.Parameters.AddWithValue("@phone",this.txtphone.Text); GetInfo(sqlcnn,sqlcmm); } } } }//查看 private void GetInfo(sqlConnection sqlcnn,sqlCommand sqlcmm) { sqlcnn.open(); sqlDataReader reader = sqlcmm.ExecuteReader(); if (reader != null) { while (reader.Read()) { this.txtClientName.Text = reader["ClientName"].ToString(); this.txtClientPhone.Text = reader["ClientPhone"].ToString(); this.txtEmail.Text = reader["Email"].ToString(); this.txtClientAddress.Text = reader["ClientAddress"].ToString(); this.txtCode.Text = reader["Code"].ToString(); this.txtCarNum.Text = reader["CarNum"].ToString(); this.txtClientNums.Text = reader["ClientNums"].ToString(); this.txtCattype.Text = reader["Cattype"].ToString(); this.txtShopid.Text = reader["ShopId"].ToString(); this.txtShopDateTime.Text = reader["ShopDateTime"].ToString(); } } } private void DelCus_Click(object sender,EventArgs e) { using (sqlConnection sqlcnn=new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "delete from T_Clientele where ClientName=@name"; sqlcmm.Parameters.AddWithValue("@name",this.txtClientName.Text); sqlcnn.open(); int i = sqlcmm.ExecuteNonQuery(); if (i>0) { MessageBox.Show("删除成功!"); this.txtClientName.Text = null; this.txtClientPhone.Text =null; this.txtEmail.Text = null; this.txtClientAddress.Text=null; this.txtCode.Text = null; this.txtCarNum.Text = null; this.txtClientNums.Text = null; this.txtCattype.Text = null; this.txtShopid.Text = null; this.txtShopDateTime.Text = null; } else { MessageBox.Show("删除失败!"); } } } }//删除 private void Addcus_Click(object sender,EventArgs e) { using (sqlConnection sqlcnn=new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "insert into T_Clientele values(@name,@phone,@Email,@address,@code,@CarNum,@ClientNums,@Cattype,@ShopId,@ShopDateTime)"; sqlcnn.open(); GetPams(sqlcmm); int i=sqlcmm.ExecuteNonQuery(); if (i>0) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } } } }//增加 private void GetPams(sqlCommand sqlcmm) { sqlcmm.Parameters.AddWithValue("@name",this.txtClientName.Text); sqlcmm.Parameters.AddWithValue("@phone",this.txtClientPhone.Text); sqlcmm.Parameters.AddWithValue("@Email",this.txtEmail.Text); sqlcmm.Parameters.AddWithValue("@address",this.txtClientAddress.Text); sqlcmm.Parameters.AddWithValue("@code",this.txtCode.Text); sqlcmm.Parameters.AddWithValue("@CarNum",this.txtCarNum.Text); sqlcmm.Parameters.AddWithValue("@ClientNums",this.txtClientNums.Text); sqlcmm.Parameters.AddWithValue("@Cattype",this.txtCattype.Text); sqlcmm.Parameters.AddWithValue("@ShopId",this.txtShopid.Text); sqlcmm.Parameters.AddWithValue("@ShopDateTime",this.txtShopDateTime.Text); } private void btnUpdate_Click(object sender,EventArgs e) { using (sqlConnection sqlcnn=new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "update T_Clientele set ClientName=@name,ClientPhone=@phone,Email=@Email,ClientAddress=@address,Code=@code,CarNum=@CarNum,ClientNums=@ClientNums,Cattype=@Cattype,ShopId=@ShopId,ShopDateTime=@ShopDateTime"; sqlcnn.open(); GetPams(sqlcmm); int i = sqlcmm.ExecuteNonQuery(); if (i>0) { MessageBox.Show("更改成功!"); } else { MessageBox.Show("更改失败!"); } } } }//更改 } }

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...