using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindGridView();
}
private string GetConnectionString(){
return WebConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString;
}
private void BindGridView()
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(GetConnectionString());
try
{
connection.Open();
string sqlStatement = "SELECT * FROM mytest";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{ dt.Rows[i][1] = ((string)dt.Rows[i][1]).Substring(0,1)+"O O"; }
//ds.Tables["test"].Rows[e.RowIndex]["test_time"] = my_test_time.Text;
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}
private void PrintRows(DataSet dataSet)
{
// For each table in the DataSet, print the row values.
foreach (DataTable table in dataSet.Tables)
{
foreach (DataRow row in table.Rows)
{
foreach (DataColumn column in table.Columns)
{
Console.WriteLine(row[column]);
}
}
}
}
}
訂閱:
張貼留言 (Atom)
讓ASP.NET網站在開發除錯時期擁有WEB.CONFIG文件轉換功能
ref: https://blog.kkbruce.net/2016/09/enabling-xml-document-transforms-for-all-asp-net-web-by-develop-time.html#.XoP1KGMzbRY
-
當 IDENTITY_INSERT 設為 OFF 時,無法將外顯值插入資料表 'xx' 的識別資料行中 id 未設定 自動遞增 設定完後 須重新 從資料庫更新模型
-
http://www.javaworld.com.tw/jute/post/view?bid=21&id=217814&tpg=9&ppg=1&sty=0&age=0
-
https://docs.microsoft.com/zh-tw/dotnet/framework/data/transactions/using-system-transactions-in-aspnet <system.web> <co...
沒有留言:
張貼留言