asp.net操作数据库相关[导入]
使用DataRelation类创建关系并利用父/子关系读取数据示例
void Page_Load(object sender, System.EventArgs e)
{
// 连接字符串和 SQL 语句
string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
string Sql = "SELECT * from Customers; SELECT * from Orders";
// 创建 Connection 和 DataAdapter 对象
SqlConnection myConn = new SqlConnection(ConnString);
SqlDataAdapter sqlAdapter = new SqlDataAdapter(Sql, myConn);
// 填充数据
DataSet dataSet = new DataSet();
sqlAdapter.Fill(dataSet, "Table");
// 命名表名
dataSet.Tables[0].TableName = "Customers";
dataSet.Tables[1].TableName = "Orders";
// 创建 Customers 和 Orders 的父/子表关系
dataSet.Relations.Add("CustomersOrders", dataSet.Tables["Customers"].Columns["CustomerID"],
dataSet.Tables["Orders"].Columns["CustomerID"]);
// 使用 GetChildRows() 方法遍历子行
foreach(DataRow custRow in dataSet.Tables["Customers"].Rows)
{
myLabel.Text += "<b>Parent Row: " + custRow["CustomerID"] + " " + custRow["CompanyName"] + "</b><br>";
myLabel.Text += "Child Row: <br>";
foreach(DataRow orderRow in custRow.GetChildRows("CustomersOrders"))
{
myLabel.Text += " " + orderRow["OrderID"] + " " + orderRow["EmployeeID"] + "<br>";
}
}
}
将DataSet的改动更新回SQL Server数据库
// 连接字符串及 SQL 语句
string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
string Sql = "SE
相关文档:
在web config中 作如下配置:
<connectionStrings>
<add name="ydycon" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=|DataDirectory|ydy.mdb" providerName="System.Data.OleDb"/>
</connectionStrings>
在.net文件中应用链接 ......
此处提供的代码用来实现当asp.net页面中的某个Button被点击后disable掉该页面中所有的Button,从而防止提交延时导致的多次提交。基于之前的onceclickbutton脚本.
//ASP.NET中防止页面多次提交的代码:javascript< script language="javascript"> < !-- function disableOtherSubmit() {
var obj = event.srcElem ......
这也许是一个小问题 但是有很多学问 不能眼高手低 我把大部分情况列出来 给大家一个提醒
float str = 987654.32F;
//Response.Write(string.Format("{0:c}", str));
//this.Label1.Text = string.Format("{0:D}", str);
//this.Label1.Text = string.Format("{0:C}", str); ......
Asp.net支持三种类型的cache
想写一个技术快速概述,可能写得太多了。技术概略的目的是以最快最简单的方式描述出技术要点,也是我希望的最有效率的知识传播方式。
1. 页面/控件cache
2. 应用程序级cache
3. 浏览器客户端cache
从实现方式来看,页面/控件cache和应用程序级cache都是存放在服务器内存里面的,随着内 ......