|
|
|
ใช่ MySQL Workbench ในการเก็บข้อมูลค่ะ อยากทราบวิธีการเก็นรูปภาพและเรียกโชว์บนเว็บ ช่วยแนะนำด้วยค่ะ |
|
|
|
|
|
|
|
แนะนำให้เก็บชือไฟล์ และรูปเก็บลงโฟเดอร์จะดีกว่าน่ะครับ
Code (VB.NET)
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<script runat="server">
Sub btnUpload_OnClick(sender As Object, e As EventArgs)
Me.pnlUpload.Visible = False
Me.pnlSave.Visible = True
If Me.fiUpload.HasFile = False Then
Me.lblText.Text = "Please select upload file!"
ELse
Me.fiUpload.SaveAs(Server.MapPath("Myfiles/"&fiUpload.FileName))
Me.lblText.Text = "<b>" &fiUpload.FileName & "</b> Uploaded.<br>"
'*** Save to Database ***'
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim strConnString,strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
strSQL = "INSERT INTO picture (PictureName) " & _
"VALUES ('" & fiUpload.FileName & "')"
objCmd = New OleDbCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
objCmd.ExecuteNonQuery()
objCmd = Nothing
objConn.Close()
objConn = Nothing
Me.hplLink1.NavigateUrl = "AspNetFileUploadToDatabase1.aspx"
Me.hplLink2.NavigateUrl = "AspNetFileUploadToDatabase2.aspx"
End IF
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - Upload files</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel id="pnlUpload" runat="server">
<asp:FileUpload id="fiUpload" runat="server"></asp:FileUpload>
<input id="btnUpload" type="button" OnServerClick="btnUpload_OnClick" value="Upload" runat="server" />
</asp:Panel>
<asp:Panel id="pnlSave" Visible="false" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label><br />
<asp:HyperLink id="hplLink1" runat="server">Upload again</asp:HyperLink>
,
<asp:HyperLink id="hplLink2" runat="server">View files</asp:HyperLink>
</asp:Panel>
</form>
</body>
</html>
Go to : ASP.NET Upload file to Database
Go to : MySQL Workbench Downloads!
ตัวอย่างนี้เป็นการใช้ Database Access ถ้าจะเปลี่ยนใช้กับ ASP.NET กับ MySQL ก็ไม่ยากครับ
|
|
|
|
|
Date :
2011-04-04 09:12:08 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าเป็นภาษาC#ล่ะคะ
|
|
|
|
|
Date :
2011-04-04 16:46:56 |
By :
หมูแดง |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<script runat="server">
void btnUpload_OnClick(Object sender, EventArgs e)
{
this.pnlUpload.Visible = false;
this.pnlSave.Visible = true;
if(!this.fiUpload.HasFile)
{
this.lblText.Text = "Please select upload file!";
}
else
{
this.fiUpload.SaveAs(Server.MapPath("Myfiles/"+fiUpload.FileName));
this.lblText.Text = "<b>" + fiUpload.FileName + "</b> Uploaded.<br>";
//*** Save to Database ***//
OleDbConnection objConn;
OleDbCommand objCmd;
String strConnString,strSQL;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("database/mydatabase.mdb") + ";";
objConn = new OleDbConnection(strConnString);
objConn.Open();
strSQL = "INSERT INTO picture (PictureName) " +
"VALUES ('" + fiUpload.FileName + "')";
objCmd = new OleDbCommand();
objCmd.Connection = objConn;
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strSQL;
objCmd.ExecuteNonQuery();
objCmd = null;
objConn.Close();
objConn = null;
this.hplLink1.NavigateUrl = "AspNetFileUploadToDatabase1.aspx";
this.hplLink2.NavigateUrl = "AspNetFileUploadToDatabase2.aspx";
}
}
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - Upload files</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel id="pnlUpload" runat="server">
<asp:FileUpload id="fiUpload" runat="server"></asp:FileUpload>
<input id="btnUpload" type="button" OnServerClick="btnUpload_OnClick" value="Upload" runat="server" />
</asp:Panel>
<asp:Panel id="pnlSave" Visible="false" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label><br />
<asp:HyperLink id="hplLink1" runat="server">Upload again</asp:HyperLink>
,
<asp:HyperLink id="hplLink2" runat="server">View files</asp:HyperLink>
</asp:Panel>
</form>
</body>
</html>
Go to : (C#) ASP.NET Upload file to Database
|
|
|
|
|
Date :
2011-04-04 17:35:09 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณค่ะ
|
|
|
|
|
Date :
2011-04-04 18:47:56 |
By :
หมูแดง |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|