asp教程.net C# 查詢資料庫教程中的日期欄位類型及查詢資料
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"");
//建立資料庫連接對象、資料庫連接字串
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from thing where date = '" + dateTimPicker1.Value + "'";
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string xierushijian = reader.GetString(1);
string dotime = reader.GetString(2);
string thingscontent = reader.GetString(3);
textBox3.Text = ("寫入時間:" + xierushijian + "做此事的時間:" + dotime + "事項內容:" + thingscontent);
}
}
%>
再一個asp.net教程查詢資料庫的內容簡單一實例
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<script runat="server" language="c#">
void Page_Load()
{
SqlConnection conn=new SqlConnection("Server=localhost;uid=sa;pwd=sa;database=student");
SqlCommand sql= new SqlCommand("select * from stu where sno='0001'",conn);
conn.Open();
SqlDataReader DReader = sql.ExecuteReader();
if(DReader.Read())
{
sno.Text = Convert.ToString(DReader["sno"]);
sname.Text = Convert.ToString(DReader["sname"]);
}
}
</script>
<html>
<head>
<title>Hello World.www.111cn.net</title>
</head>
<body>
<form runat="server">
<asp:Label id="sno" runat="server" />
<asp:Label id="sname" runat="server" />
</form>