Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How to save a file to DB in aspx?

How to save a file to DB in aspx?
[33 byte] By [sunrise] at [2007-11-9 16:24:41]
# 1 Re: How to save a file to DB in aspx?
Try this simple example to save a record in Northwind in MS SQL server:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E) {
string sConnect = "server= (local);uid=sa;pwd=;database=northwind";
string sSQL = "INSERT INTO Customers (CustomerID, CompanyName) VALUES
('AAAAA','A Company')";

SQLConnection cn = new SQLConnection(sConnect);
SQLCommand cmd= new SQLCommand(sSQL,cn);
try
{
cn.Open();
cmd.Execute();
}
catch(Exception obj)
{
Response.Write(obj.Message);
}
}
</script>

Mingyong Yang, MCP
---------
http://www.foxinternet.net/web2/myang

"sunrise" <sunrise@szu.edu.cn> wrote:
>How to save a file to DB in aspx?
>
>
>
Mingyong Yang at 2007-11-11 23:25:41 >
# 2 Re: How to save a file to DB in aspx?
I want save file to Database, for exsample a .gif file or .jpg file?

"Mingyong Yang" <myang@foxinternet.net> wrote in message
news:39efc171$1@news.dev-archive.com...
>
> Try this simple example to save a record in Northwind in MS SQL server:
>
> <%@ Import Namespace="System.Data" %>
> <%@ Import Namespace="System.Data.SQL" %>
> <script language="C#" runat="server">
> void Page_Load(Object Src, EventArgs E) {
> string sConnect = "server=
(local);uid=sa;pwd=;database=northwind";
> string sSQL = "INSERT INTO Customers (CustomerID, CompanyName)
VALUES
> ('AAAAA','A Company')";
>
> SQLConnection cn = new SQLConnection(sConnect);
> SQLCommand cmd= new SQLCommand(sSQL,cn);
> try
> {
> cn.Open();
> cmd.Execute();
> }
> catch(Exception obj)
> {
> Response.Write(obj.Message);
> }
> }
> </script>
>
> Mingyong Yang, MCP
> ---------
> http://www.foxinternet.net/web2/myang
>
> "sunrise" <sunrise@szu.edu.cn> wrote:
> >How to save a file to DB in aspx?
> >
> >
> >
>
sunrise at 2007-11-11 23:26:52 >
# 3 Re: How to save a file to DB in aspx?
How about saving the URL that points to the .gif file to the database?

Mingyong Yang, MCP
----------
http://www.foxinternet.net/web2/myang

"sunrise" <sunrise@szu.edu.cn> wrote:
>I want save file to Database, for exsample a .gif file or .jpg file?
>
>"Mingyong Yang" <myang@foxinternet.net> wrote in message
>news:39efc171$1@news.dev-archive.com...
>>
>> Try this simple example to save a record in Northwind in MS SQL server:
>>
>> <%@ Import Namespace="System.Data" %>
>> <%@ Import Namespace="System.Data.SQL" %>
>> <script language="C#" runat="server">
>> void Page_Load(Object Src, EventArgs E) {
>> string sConnect = "server=
>(local);uid=sa;pwd=;database=northwind";
>> string sSQL = "INSERT INTO Customers (CustomerID, CompanyName)
>VALUES
>> ('AAAAA','A Company')";
>>
>> SQLConnection cn = new SQLConnection(sConnect);
>> SQLCommand cmd= new SQLCommand(sSQL,cn);
>> try
>> {
>> cn.Open();
>> cmd.Execute();
>> }
>> catch(Exception obj)
>> {
>> Response.Write(obj.Message);
>> }
>> }
>> </script>
>>
>> Mingyong Yang, MCP
>> ---------
>> http://www.foxinternet.net/web2/myang
>>
>> "sunrise" <sunrise@szu.edu.cn> wrote:
>> >How to save a file to DB in aspx?
>> >
>> >
>> >
>>
>
>
Mingyong Yang at 2007-11-11 23:27:44 >