我想为每一列赋予不同的 dwign 类(如在 CSS 中)。例如,用户名列以蓝色绘制,放大字体为 30px,将密码绘制为红色,并将其字体更改为“times new romans,12px”。我有以下cs代码与SQL中的数据库通信:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public class MyAdoHelper
{
public static SqlConnection ConnectToDB(string fileName)
{
string path = HttpContext.Current.Server.MapPath("App_Data/");
path += "Database.mdf";
string connString = @"Data Source=.\SQLEXPRESS;AttachDbFileName=" +
path + ";Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(connString);
return conn;
}
public static void DoQuery(string fileName, string sql)
{
SqlConnection conn = ConnectToDB(fileName);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
com.ExecuteNonQuery();
conn.Close();
}
public static DataTable ExecuteDataTable(string fileName, string sql)
{
SqlConnection conn = ConnectToDB(fileName);
conn.Open();
DataTable dt = new DataTable();
SqlDataAdapter tableAdapter = new SqlDataAdapter(sql, conn);
tableAdapter.Fill(dt);
return dt;
}
public static string printDataTable(string fileName, string sql)
{
DataTable dt = ExecuteDataTable(fileName, sql);
string printStr = "<table border='1'>";
foreach (DataRow row in dt.Rows)
{
printStr += "<tr>";
foreach (object myItemArray in row.ItemArray)
{
printStr += "<td>" + myItemArray.ToString() + "</td>";
}
printStr += "</tr>";
}
printStr += "</table>";
return printStr;
}
public static bool IsExist(string fileName, string sql)
{
bool found;
SqlConnection conn = ConnectToDB(fileName);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
SqlDataReader data = com.ExecuteReader();
found = (bool)data.Read();
conn.Close();
return found;
}
public static int RowsAffected(string fileName, string sql)
{
SqlConnection conn = ConnectToDB(fileName);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
int rowsA = com.ExecuteNonQuery();
conn.Close();
return rowsA;
}
}
我想改变“printdataTable”,但我不知道。