C 對資料庫各種操作

2021-06-04 08:21:32 字數 3577 閱讀 2406

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

private void getid()

}}//獲取客戶姓名對應的id號

private void getall()

}}//給datagridview填充資料庫中的資料

private void btnlook_click(object sender, eventargs e)

else if (dt.rows.count <= 0)

else}}

}}}}

else

}else if(this.checkphone.checked)

else if (dt.rows.count <=0)

else}}

}else if (this.checkname.checked && this.checkphone.checked)}}

else

}//檢視

private void getinfo(sqlcommand sqlcmm)

}reader.close();

}//給客戶詳細資訊賦值

private void delcus_click(object sender, eventargs e)

}sqlcmm.parameters.addwithvalue("@name",this.txtclientname.text);

int n = sqlcmm.executenonquery();

if (n>0)

else}}

}//刪除

private void tonull()

//清空資料

private void addcus_click(object sender, eventargs e)

else

}using (sqlcommand sqlcmm1 = sqlcnn.createcommand())

sqlcmm2.commandtext = "select id from t_user where username=@name";

sqlcmm2.parameters.addwithvalue("@name",class1.username);

object a = sqlcmm2.executescalar();

int id = convert.toint32(a);

sqlcmm1.commandtext = "insert into t_record(operperson,clientid,suggest,memo) values(@person,@clientid,@suggest,@memo)";

sqlcmm1.parameters.addwithvalue("@person",id);

sqlcmm1.parameters.addwithvalue("@clientid", convert.toint32(this.labid.text));

sqlcmm1.parameters.addwithvalue("@suggest", this.txtsuggest.text);

sqlcmm1.parameters.addwithvalue("@memo", this.txtcomment.text);

sqlcmm1.executenonquery();

tonull();}}

}}//新增

private void getpams(sqlcommand sqlcmm)

//填充佔位符

private void btnupdate_click(object sender, eventargs e)

//else//}

using (sqlcommand sqlcmm1=sqlcnn.createcommand())

else }

}}//更改

private void datagridview1_cellmousedoubleclick(object sender, datagridviewcellmouseeventargs e)

}//雙擊顯示另一選項卡

private void btn_add_click(object sender, eventargs e)

else

}using (sqlcommand sqlcmm1 = sqlcnn.createcommand())

sqlcmm2.commandtext = "select id from t_user where username=@name";

sqlcmm2.parameters.addwithvalue("@name", class1.username);

object a = sqlcmm2.executescalar();

int id = convert.toint32(a);

sqlcmm1.commandtext = "insert into t_record(operperson,clientid,suggest,memo) values(@person,@clientid,@suggest,@memo)";

sqlcmm1.parameters.addwithvalue("@person", id);

sqlcmm1.parameters.addwithvalue("@clientid", convert.toint32(this.labid.text));

sqlcmm1.parameters.addwithvalue("@suggest", this.datagridview1.currentrow.cells[11].value.tostring());

sqlcmm1.parameters.addwithvalue("@memo", this.datagridview1.currentrow.cells[12].value.tostring());

sqlcmm1.executenonquery();}}

}}//新增(datagridview)

private void getcellvalue(sqlcommand sqlcmm)

//獲取datagridview中選中行的單元格的值

private void btn_update_click(object sender, eventargs e)

//else

if (i == 0)

}using (sqlcommand sqlcmm1 = sqlcnn.createcommand())

else}}

}//更改(datagridview)

private void refresh_click(object sender, eventargs e)

//重新整理}}

C 對資料庫各種操作

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...

Asp Sql 對資料庫的各種操作

查詢方法 1 set rsworkuserinfo server.createobject adodb.recordset strsql select usersid,loginname,username,password strsql strsql from users strsql strsql...

c 對資料庫的操作

1.首先需要引用 using system.data.sqlclient 2.建立連線 sqlconnection connection new sqlconnection connection.connectionstring data source ip位址 initial catalog 資料...