日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

gridview 动态数据操作

發(fā)布時間:2023/12/31 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 gridview 动态数据操作 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
自定義數(shù)據(jù)庫操作類:如下: 代碼 using?System;
using?System.Data;
using?System.Configuration;
using?System.Web;
using?System.Web.Security;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?System.Web.UI.HtmlControls;
using?System.Data.SqlClient;

///?<summary>
///?BasedDb?的摘要說明
///?</summary>
public?class?BaseDb
{
????
//獲取數(shù)據(jù)庫連接字符串?
????private?string?connectionstring?=?System.Configuration.ConfigurationManager.AppSettings["connectionstring"].ToString();
????
public?BaseDb()
????{
????????
//
????????
//?TODO:?在此處添加構(gòu)造函數(shù)邏輯
????????
//
????}

????
public?System.Data.DataSet?getdatabydataset(string?sqlstr)
????{
????????
//?功能:根據(jù)傳入的SQL語句腳本,以Dataset對象形式返回數(shù)據(jù)集??
????????
//?以Dataset對象形式返回數(shù)據(jù)集

????????SqlConnection?conn?
=?new?SqlConnection();
????????conn.ConnectionString?
=?connectionstring;

????????
//進行錯誤處理,如果出現(xiàn)異常,則拋出異常
????????try
????????{
????????????conn.Open();
????????}
????????
catch?(Exception?e)
????????{
????????????
throw?new?Exception(e.Message,?e);
????????}
????????
//?創(chuàng)建Dataset對象,用于接收數(shù)據(jù)庫返回記錄集
????????DataSet?ds?=?new?DataSet();
????????SqlDataAdapter?sda?
=?new?SqlDataAdapter(sqlstr,?conn);
????????
try
????????{
????????????
//對Dataset記錄集進行賦值
????????????sda.Fill(ds);
????????}
????????
catch?(Exception?err)
????????{
????????????
throw?new?Exception(err.Message,?err);
????????}
????????
//調(diào)用方法關(guān)閉數(shù)據(jù)庫連接
????????closeconnection(conn);
????????
//以Dataset形式返回記錄集
????????return?ds;
????}

????
public?System.Data.DataTable?getdatabydatatable(string?sqlstr)
????{
????????
//功能:根據(jù)傳入的SQL語句腳本,以DataTable?對象形式返回數(shù)據(jù)集
????????return?getdatabydataset(sqlstr).Tables[0];
????}

????
public?string?ExecuteSql(string?sqlstr)
????{
????????
//功能:執(zhí)行Sql腳夫本操作,無返回記錄集。該方法適用于新增、修改、刪除等操作。
????????
//初始化異常描述變量
????????string?errdesc?=?"";
????????SqlConnection?conn?
=?new?SqlConnection();
????????conn.ConnectionString?
=?connectionstring;
????????conn.Open();
????????
//創(chuàng)建命令對象
????????SqlCommand?cmd?=?new?SqlCommand();
????????cmd.Connection?
=?conn;
????????
//將Sql腳本語句賦給命令對象
????????cmd.CommandText?=?sqlstr;
????????
try
????????{
????????????cmd.ExecuteNonQuery();
????????}
????????
catch?(Exception?err)
????????{
????????????errdesc?
=?err.Message.ToString();
????????????
throw?new?Exception(err.Message,?err);
????????}
????????closeconnection(conn);
????????
return?errdesc;
????}

????
private?void?closeconnection(SqlConnection?conn)
????{
????????
//功能:關(guān)閉數(shù)據(jù)庫連接對象
????????conn.Close();
????????
//回收數(shù)據(jù)庫連接所占系統(tǒng)資源
????????conn.Dispose();
????}

????
public?void?Update(string?strAdminPassword,?string?strAdminiName)
????{
????????
//功能:更新數(shù)據(jù)
???????string?strSql=?"UPDATE?[Administrator]?SET?[Admin_password]='"?+?strAdminPassword +"'?WHERE?[Admin_name]?='"+strAdminiName +"'";
???????ExecuteSql(strSql);
???????
//SqlConnection?conn?=?new?SqlConnection();
???????
//conn.ConnectionString?=?connectionstring;
???????
//conn.Open();
???????////創(chuàng)建命令對象
???????//SqlCommand?cmd?=?new?SqlCommand();
???????
//cmd.Connection?=?conn;
???????////將Sql腳本語句賦給命令對象
???????//cmd.CommandText?=?strSql;
???????
//try
???????
//{
???????
//????cmd.ExecuteNonQuery();

??????????
???????
//}
???????
//catch?(Exception?err)
???????
//{
???????????
???????
//????throw?new?Exception(err.Message,?err);
???????
//}
???????
//closeconnection(conn);
?????????
????}
}
? ? //動態(tài)添加數(shù)據(jù) ? 添加數(shù)據(jù)的前臺代碼 代碼 <table?style="z-index:?106;?left:?346px;?width:?333px;?position:?absolute;?top:?64px">
????
<tr>
????????
<td?style="width:?104px">
????????
</td>
????????
<td>
????????
</td>
????????
<td?style="width:?108px">
????????
</td>
????
</tr>
????
<tr>
????????
<td?style="width:?104px;?height:?21px;">
????????????管理員賬號
</td>
????????
<td?style="height:?21px">
????????????密碼
</td>
????????
<td?style="width:?108px;?height:?21px;">
????????
</td>
????
</tr>
????
<tr>
????????
<td?style="width:?104px">
????????????
<asp:TextBox?ID="Adminname"?runat="server"?Style="z-index:?100;?left:?6px;?position:?absolute;
????????????????top:?46px"?Width="102px"?MaxLength="20"></asp:TextBox>
????????</td>
????????
<td>
????????????
<asp:TextBox?ID="Adminpassword"?runat="server"?Style="z-index:?100;?left:?116px;
????????????????position:?absolute;?top:?48px"?Width="102px"?MaxLength="20"></asp:TextBox>
????????</td>
????????
<td?style="width:?108px">
????????????
<asp:Button?ID="Add"?runat="server"?OnClick="Add_Click"?Style="z-index:?100;?left:?237px;
????????????????position:?absolute;?top:?47px"?Text="添加"?Width="64px"?/>
????????</td>
????
</tr>
</table>

?

? ? ?

?

?

?

后臺代碼

轉(zhuǎn)載于:https://www.cnblogs.com/85538649/archive/2010/03/26/wtq.html

總結(jié)

以上是生活随笔為你收集整理的gridview 动态数据操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。