10月 27, 2006

.net 2.0連結Mysql

最近在GOdaddy租了.net的虛擬主機,規格不錯價格也划算
我租的是沒有MSsql的版本,只能用mysql或access
godaddy提供了OleDB和ODBC的方法供.net連結mysql,不過我都試不出來orz...
到google搜尋了一下,發現多數人都用mysql專為.net寫的driver來連mysql db
方法如下
1.在專案中建立/bin資料夾
2.將MySql.Data.dll放置/bin資料夾
3.在程式中引用MySql.Data.dll(vb寫法:)
以下是code

檔案:http://joehwang.myweb.hinet.net/xuite/DonetAndMysql.zip
  
<%@Page Language="VB" CodePage="65001" %>
<%@Import Namespace = "MySql.Data.MySqlClient" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myConn As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As Data.DataSet
Dim strSQL As String
'建立連接
myConn = New MySqlConnection("server=mysql213.secureserver.net; user id=joehwang; password=b0410; database=joehwang;CHARSET=big5")
myConn.Open()
Dim mycmd As MySqlCommand
mycmd = New MySqlCommand("Update member Set name = '一' where id = 1", myConn)
mycmd.ExecuteNonQuery()

strSQL = "Select * FROM member;"
myDataAdapter = New MySqlDataAdapter(strSQL, myConn)
myDataSet = New Data.DataSet

myDataAdapter.Fill(myDataSet, "mytable")
GridView1.DataSource = myDataSet.Tables("mytable").DefaultView
GridView1.DataBind()
myConn.Close()

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" lang="zh-tw">
<title>未命名頁面</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
測試
</div>
</form>
</body>
</html>



10月 26, 2006

Flash跨網域讀取資料

跨網域讀取資料
AS:

System.security.loadPolicyFile("http://cn.english.tw/include/forfestival/crossdomain.xml");
//跨網域原則檔案
//此swf網域為tw.english21.us要跨網域讀取cn.english21.us,因此在cn.english.tw/include/forfestival裡要放crossdomain.xml
//crossdomain.xml上記載允許讀取的domain

crossdomain.xml:

//星號代表該網域全部允許

10月 13, 2006

偽.flash播放器

想來想去還是這標題最貼切
工作上要用flash播放wma,不過flash不支援,所以就用ExternalInterface呼叫mediaplayer物件,利用mediaplayer本身提供的方法控制囉,也因為mediaplayer物件的關係所以不能支援firefox。

DEMO
Source

10月 02, 2006

最近在學寫ASP.net,感覺不錯!
不過既然datagrid有支援分頁怎麼datalist不順便支援?
流程是Sqldatasource控制項→PagedDataSource控制項→DataList控制項
參考"廖瑞奇站長的文章-用Repeater分頁"撰寫以下程式

範例:http://vip.blueshop.com.tw/joehwang/flower/default.aspx
下載:http://joehwang.myweb.hinet.net/xuite/page_datalist.zip


default.aspx



detail.aspx
  
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim id As Integer
id = Request.QueryString("id")

Dim db1 As New SqlDataSource
db1.ProviderName = "System.Data.OleDb"
db1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|flower.mdb;"
db1.SelectCommand = "select * from [flowers_plants] where fp_id= ? "
db1.SelectParameters.Add("fp_id", id)
Dim dv As Data.DataView = db1.Select(New DataSourceSelectArguments)
Me.FormView1.DataSource = dv

Me.FormView1.DataBind()
End Sub


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>未命名頁面</title>
</head>
<body>
<form id="form1" runat="server">
<div align=center>
<asp:FormView ID="FormView1" runat="server" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical">
<ItemTemplate>

<img src=small/<%# DataBinder.Eval(Container.DataItem, "s_file") %> /><br />
ID:
<asp:Label ID="fp_idLabel" runat="server" Text='<%# Bind("fp_id") %>'></asp:Label><br />
名稱:
<asp:Label ID="c_nameLabel" runat="server" Text='<%# Bind("c_name") %>'></asp:Label><br />
學名:
<asp:Label ID="e_nameLabel" runat="server" Text='<%# Bind("e_name") %>'></asp:Label><br />
家族:
<asp:Label ID="familyLabel" runat="server" Text='<%# Bind("family") %>'></asp:Label><br />
別名:
<asp:Label ID="aliasLabel" runat="server" Text='<%# Bind("alias") %>'></asp:Label><br />
科名:
<asp:Label ID="scientific_nameLabel" runat="server" Text='<%# Bind("scientific_name") %>'>
</asp:Label><br />
類別
<asp:Label ID="classLabel" runat="server" Text='<%# Bind("class") %>'></asp:Label><br />

</ItemTemplate>
<FooterStyle BackColor="#CCCC99" />
<EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F7DE" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />


</asp:FormView>

</div>
</form>
</body>
</html>