Showing posts with label online. Show all posts
Showing posts with label online. Show all posts

Monday, March 26, 2012

Image upload problem into database

Hi guys,

I'm currently trying to insert image into my SQL db. I have tried a number of methods that were posted online, and so far with no luck.

My current code reads:


Dim conn As New Data.SqlClient.SqlConnection()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("MainDBConnection").ToString
conn.Open()

Dim cmd As New Data.SqlClient.SqlCommand("SP_SAVEImage", conn)

cmd.CommandType = Data.CommandType.StoredProcedure

Dim nUserID As New Data.SqlClient.SqlParameter("@.nUserID", Data.SqlDbType.Int)
nUserID.Value = "1"

Dim nAlbumID As New Data.SqlClient.SqlParameter("@.nAlbumID", Data.SqlDbType.Int)
nAlbumID.Value = "1"

Dim sDescription As New Data.SqlClient.SqlParameter("@.sDescription", Data.SqlDbType.VarChar, 50)
sDescription.Value = "image1"

Dim sImageName As New Data.SqlClient.SqlParameter("@.sImageName", Data.SqlDbType.VarChar, 50)
sImageName.Value = sImageName

Dim sImageType As New Data.SqlClient.SqlParameter("@.sImageType", Data.SqlDbType.VarChar, 50)
sImageType.Value = fileType

Dim sImageData As New Data.SqlClient.SqlParameter("@.sImageData", Data.SqlDbType.Image, uploadedFile.Length)
sImageData.Value = uploadedFile

cmd.Parameters.Add(nUserID)
cmd.Parameters.Add(nAlbumID)
cmd.Parameters.Add(sDescription)
cmd.Parameters.Add(sImageName)
cmd.Parameters.Add(sImageType)
cmd.Parameters.Add(sImageData)

Dim reader1 As Data.SqlClient.SqlDataReader

reader1 = cmd.ExecuteReader

Running through debug, everything runs up until the last line, where an error is caught saying : Failed to convert parameter value from a SqlParameter to a String

I reckon it's to do with the input sImageData being input as a byte array - but I can't seem to find a way around it.Angry


Any help greatly appreciated!!

Dim sImageName As New Data.SqlClient.SqlParameter("@.sImageName", Data.SqlDbType.VarChar, 50)
sImageName.Value = sImageName

You are setting an SqlParameter equal to a string value. Must be a typeo. Fix and retry.

|||

THANK YOU!!!!!!

I feel such an idiot now!! I've been looking at this code for so long I couldn't see the obvious.

I had honestly just given up on the idea of saving my data this way; but decided to check the post before going to bed - I can sleep well now knowing at least some of my code works! lol.

Cheers mate

Friday, March 9, 2012

IIS for SQL Server - problem

I configured IIS Virtual Directory Management for SQL Server Utility as
is described in Books Online, but I receive 404 error.
I gave everywhere everyone full access where I can…. But I don’t know
where to look for an error…
IIS seems to work properly because other WWW are working OK.
My SQL Server is from Small Business Server, maybe it shouldn’t work
under SBS?
Hello,
Please let me know the SQL server version you use. For example, SQL server
2000 Standard Edition with SP3. I suggest that you perform the following
steps to narrow down the issue:
1. Make sure your IIS server works fine.
2. Create the virtual directory <nwind>. For more information about how to
configure a virtual directory by using the IIS Virtual Directory Management
SQL Server utility, visit the following MSDN Web site:
http://msdn.microsoft.com/library/en..._xml1_2xvd.asp
3. Open Microsoft Internet Explorer and locate:
http://IISServer/nwind?sql=SELECT+*+...TO&roo t=root
If you receive the error message "HTTP error 404 - File or directory not
found", please perform the steps in the following article 810784:
810784 Error message "HTTP error 404 - File or directory not found" occurs
when
http://support.microsoft.com/?id=810784
Check the issue again. I hope the information is helpful.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
================================================== ===
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.

IIS for SQL Server - problem

I configured IIS Virtual Directory Management for SQL Server Utility as
is described in Books Online, but I receive 404 error.
I gave everywhere everyone full access where I can…. But I don’t know
where to look for an error…
IIS seems to work properly because other WWW are working OK.
My SQL Server is from Small Business Server, maybe it shouldn’t work
under SBS?Hello,
Please let me know the SQL server version you use. For example, SQL server
2000 Standard Edition with SP3. I suggest that you perform the following
steps to narrow down the issue:
1. Make sure your IIS server works fine.
2. Create the virtual directory <nwind>. For more information about how to
configure a virtual directory by using the IIS Virtual Directory Management
SQL Server utility, visit the following MSDN Web site:
http://msdn.microsoft.com/library/e...c_xml1_2xvd.asp
3. Open Microsoft Internet Explorer and locate:
http://IISServer/nwind? sql=SELECT+...r />
&root=root
If you receive the error message "HTTP error 404 - File or directory not
found", please perform the steps in the following article 810784:
810784 Error message "HTTP error 404 - File or directory not found" occurs
when
http://support.microsoft.com/?id=810784
Check the issue again. I hope the information is helpful.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
========================================
=============
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

Sunday, February 19, 2012

IIF Function

I've been looking at the online help and it appears that
this statement should function as follows:
Select IIf(1 > 0 , 'Yes', 'No')
If 1 is greater than 0, Yes should be returned, if not
then No
Sql returns an error message: Incorrect syntax near '>'
Any Ideas?
Thanks
You must be looking at help for MS Access or Excel or something. There is
no such thing as IIF in SQL Server. Maybe try CASE:
SELECT CASE WHEN 1 > 0 THEN 'Yes' ELSE 'No' END
"Raghib" <anonymous@.discussions.microsoft.com> wrote in message
news:100801c4f1fe$f73d1860$a301280a@.phx.gbl...
> I've been looking at the online help and it appears that
> this statement should function as follows:
> Select IIf(1 > 0 , 'Yes', 'No')
>
> If 1 is greater than 0, Yes should be returned, if not
> then No
> Sql returns an error message: Incorrect syntax near '>'
> Any Ideas?
> Thanks
>
|||If you search for IIF in SQL Server Books Online, you will indeed find it.
However, you have to look at the title (or location) and realize it is for
Analysis Services only.
This is not a TSQL function, but rather an MDX function.
HTH
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Aaron Bertrand [MVP]" <aaron@.TRASHaspfaq.com> wrote in message
news:%23GAGeFg8EHA.2600@.TK2MSFTNGP09.phx.gbl...
> You must be looking at help for MS Access or Excel or something. There is
> no such thing as IIF in SQL Server. Maybe try CASE:
> SELECT CASE WHEN 1 > 0 THEN 'Yes' ELSE 'No' END
>
>
> "Raghib" <anonymous@.discussions.microsoft.com> wrote in message
> news:100801c4f1fe$f73d1860$a301280a@.phx.gbl...
>

IIF Function

I've been looking at the online help and it appears that
this statement should function as follows:
Select IIf(1 > 0 , 'Yes', 'No')
If 1 is greater than 0, Yes should be returned, if not
then No
Sql returns an error message: Incorrect syntax near '>'
Any Ideas?
ThanksYou must be looking at help for MS Access or Excel or something. There is
no such thing as IIF in SQL Server. Maybe try CASE:
SELECT CASE WHEN 1 > 0 THEN 'Yes' ELSE 'No' END
"Raghib" <anonymous@.discussions.microsoft.com> wrote in message
news:100801c4f1fe$f73d1860$a301280a@.phx.gbl...
> I've been looking at the online help and it appears that
> this statement should function as follows:
> Select IIf(1 > 0 , 'Yes', 'No')
>
> If 1 is greater than 0, Yes should be returned, if not
> then No
> Sql returns an error message: Incorrect syntax near '>'
> Any Ideas?
> Thanks
>|||If you search for IIF in SQL Server Books Online, you will indeed find it.
However, you have to look at the title (or location) and realize it is for
Analysis Services only.
This is not a TSQL function, but rather an MDX function.
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Aaron Bertrand [MVP]" <aaron@.TRASHaspfaq.com> wrote in message
news:%23GAGeFg8EHA.2600@.TK2MSFTNGP09.phx.gbl...
> You must be looking at help for MS Access or Excel or something. There is
> no such thing as IIF in SQL Server. Maybe try CASE:
> SELECT CASE WHEN 1 > 0 THEN 'Yes' ELSE 'No' END
>
>
> "Raghib" <anonymous@.discussions.microsoft.com> wrote in message
> news:100801c4f1fe$f73d1860$a301280a@.phx.gbl...
>

IIF Function

I've been looking at the online help and it appears that
this statement should function as follows:
Select IIf(1 > 0 , 'Yes', 'No')
If 1 is greater than 0, Yes should be returned, if not
then No
Sql returns an error message: Incorrect syntax near '>'
Any Ideas?
ThanksYou must be looking at help for MS Access or Excel or something. There is
no such thing as IIF in SQL Server. Maybe try CASE:
SELECT CASE WHEN 1 > 0 THEN 'Yes' ELSE 'No' END
"Raghib" <anonymous@.discussions.microsoft.com> wrote in message
news:100801c4f1fe$f73d1860$a301280a@.phx.gbl...
> I've been looking at the online help and it appears that
> this statement should function as follows:
> Select IIf(1 > 0 , 'Yes', 'No')
>
> If 1 is greater than 0, Yes should be returned, if not
> then No
> Sql returns an error message: Incorrect syntax near '>'
> Any Ideas?
> Thanks
>|||If you search for IIF in SQL Server Books Online, you will indeed find it.
However, you have to look at the title (or location) and realize it is for
Analysis Services only.
This is not a TSQL function, but rather an MDX function.
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Aaron Bertrand [MVP]" <aaron@.TRASHaspfaq.com> wrote in message
news:%23GAGeFg8EHA.2600@.TK2MSFTNGP09.phx.gbl...
> You must be looking at help for MS Access or Excel or something. There is
> no such thing as IIF in SQL Server. Maybe try CASE:
> SELECT CASE WHEN 1 > 0 THEN 'Yes' ELSE 'No' END
>
>
> "Raghib" <anonymous@.discussions.microsoft.com> wrote in message
> news:100801c4f1fe$f73d1860$a301280a@.phx.gbl...
>> I've been looking at the online help and it appears that
>> this statement should function as follows:
>> Select IIf(1 > 0 , 'Yes', 'No')
>>
>> If 1 is greater than 0, Yes should be returned, if not
>> then No
>> Sql returns an error message: Incorrect syntax near '>'
>> Any Ideas?
>> Thanks
>