|
OK I have taken you advice from the website and I am still having issues with the Invalid Parameter. What is wrong?
private void pictureBox3_DoubleClick(object sender, EventArgs e)
{
intASUserListSelectedIndex = lbxAssistSuiteUserList.SelectedIndex;
bool FoundUser = false;
FileDialog fldlg = new OpenFileDialog();
if (lbxAssistSuiteUserList.SelectedIndex > -1)
{
try
{
fldlg.InitialDirectory = @":C\";
fldlg.Filter = "Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif|(*.gif)|*.gif|(*.jpg)|*.jpg|(*.jpeg)|*.jpeg|(*.bmp)|*.bmp|(*.wmf)|*.wmf|(*.png)|*.png";
if (fldlg.ShowDialog() == DialogResult.OK)
{
imagename = fldlg.FileName;
Bitmap newimg = new Bitmap(imagename);
pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox3.Image =(Image)newimg;
pictureBox3.Refresh();
lbxAssistSuiteUserList.SelectedIndex = intASUserListSelectedIndex;
btnUpdateAssistUsers_Click(sender, e);
lbxAssistSuiteUserList.SelectedIndex = intASUserListSelectedIndex;
updatedata();
}
fldlg = null;
lbxAssistSuiteUserList.SelectedIndex = intASUserListSelectedIndex;
}
catch (System.ArgumentException ae)
{
imagename = " ";
MessageBox.Show(ae.Message.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
private void updatedata()
{
SqlCommand cmd;
bool FoundMe = false;
int UserIndex = -1;
try
{
if (imagename != "")
{
SqlConnection cn = new SqlConnection(WhatIsMyConnectionString);
for (i = 0; i < ApplicationUsersArray.Count; i++)
{
if (((DomainUsersClass)ApplicationUsersArray[i]).WindowsLogonName == lbxAssistSuiteUserList.Items[lbxAssistSuiteUserList.SelectedIndex].ToString())
{
FoundMe = true;
break;
}
}
if (FoundMe = true)
{
if (((DomainUsersClass)ApplicationUsersArray[i]).PicIndex == "")
{
UserIndex = Convert.ToInt32(((DomainUsersClass)ApplicationUsersArray[i]).Index);
cmd = new SqlCommand("INSERT INTO tblApplicationUsersPic (id_image,BLOBData) VALUES ('" + UserIndex.ToString() + "'," + " @BLOBData)", cn);
}
else
{
UserIndex = Convert.ToInt32(((DomainUsersClass)ApplicationUsersArray[i]).Index);
cmd = new SqlCommand("update tblApplicationUsersPic set pic = @BLOBData where id_image = '" + UserIndex.ToString() + "' ", cn);
}
}
else
{
MessageBox.Show("We have a serious problem. This should Never Happen. \n The Array did not find the correct users to grab their index for the Picture. \n The Application will now quit.");
return;
}
String strBLOBFilePath = @imagename;
FileStream fsBLOBFile = new FileStream(strBLOBFilePath,FileMode.Open, FileAccess.Read);
Byte[] bytBLOBData = new Byte[fsBLOBFile.Length];
fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
fsBLOBFile.Close();
SqlParameter prm = new SqlParameter("@BLOBData", SqlDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, false,
0, 0, null, DataRowVersion.Current, bytBLOBData);
cmd.Parameters.Add(prm);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
if (FoundMe = true)
{
SQLUpdate(WhatIsMyConnectionString, "tblApplicationUsers", "tblApplicationUsersPic_idx = (Select idx_tblApplicationUserPic from tblApplicationUsersPic where id_image = '" + UserIndex.ToString() + "') ","delflag = 0 and idx_tblApplicationUsers = '" + UserIndex.ToString() + "' ");
}
}
}
catch (System.ArgumentException ae)
{
imagename = " ";
MessageBox.Show(ae.Message.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
|
|
|
|
|
Luc has just posted a reply, so see if that helps you and come back again if not.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I have tried several different ways of adding the image to the database and the image does end up in the database but the c# application always errors saying "Parameter is invalid" I do not understand what I am doing wrong.
|
|
|
|
|
Hi,
yes that is very readable now.
disclaimer: I'm not a database specialist, I did some MySQL, a bit of SQL Server,
and no Oracle. I did save and restore images to MySQL once, that worked well.
1.
Assuming your image data will be stored as BLOB, the process indeed is:
- load the file data into a byte array
- construct and execute the SQL command that takes the byte array as a BLOB parameter
(I think your code is off in that aspect)
Suggestion: don't ever show Exception.Message, always show Exception.ToString(),
as it provides much more useful information, including line numbers.
And tell your IDE to always show line numbers in edit windows, see here.[^]
In future posts, please paste the exact exception text and indicate the line that caused it.
Maybe you need to tell the SqlCommand you are adding a BLOB value; so instead of
using AddWithValue, do an Add first (with appropriate DbType), then set the Value
of that new parameter to picByte.
2.
Once storing an image seems to work, I recommend you check your data really got stored in the database by somehow verifying the size of the record; without the image it would be a few dozen bytes; with image it should be thousands (roughly, see file size).
3.
Retrieving an image is almost identical; you don't need to create a file, as there is a Bitmap constructor that takes a byte array.
4.
In general, make Google your friend.
I tried: C# save image to oracle
and found many, maybe you'll like this one.[^]
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
hi friends i want Active X Controls for C# windows application...so please provide any link to download controls for purely C# windows application..
Txs in advance...
|
|
|
|
|
There are no controls "purely for C# applications". Controls are for a specific purpose and are usually exposed through COM. So, you can use just about any control you want in your app. It's the applications requirements that determine the control you're going to use, not the language you use it in.
|
|
|
|
|
|
Has someone written this?
I note that it exists in System.IO.Packaging, supported by Vista only, as PackUriHelper.GetRelativeUri.
But I'm surprised it doesn't exist in System.IO.Path. Anyone have a (working!) implementation?
Marc
Will work for food.
Interacx
I'm not overthinking the problem, I just felt like I needed a small, unimportant, uninteresting rant! - Martin Hart Turner
|
|
|
|
|
Hi Marc,
I think you have to expand on the specifications.
Anyway, isn't it just about locating one (the last?) backslash?
IMO the last one is what Path.GetFileName() does.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: I think you have to expand on the specifications.
Taking an example from GetRelativeUri:
If my application is executing out of /mydoc/markup/ (which I can provide, of course) and I open the file /mydoc/picture.jpg, I want the relative path to be ../picture.jpg.
If I open a file in /mydoc/foobar/picture.jpg, I want the relative path to be ../foobar/picture.jpg.
Maybe it really is as easy as finding the common path and figuring out how many levels to go up and then branch.
Marc
Will work for food.
Interacx
I'm not overthinking the problem, I just felt like I needed a small, unimportant, uninteresting rant! - Martin Hart Turner
|
|
|
|
|
OK,
I had a look inside GetRelativeUri and it expanded to
return new Uri(PathDifference(this.AbsolutePath, uri.AbsolutePath, !this.IsUncOrDosPath) + uri.GetParts(UriComponents.Fragment | UriComponents.Query, UriFormat.UriEscaped), UriKind.Relative);
So that is probably not the solution.
I think along these lines (not tested, and not throwing when target shorter than ref):
public static string MakeRelativePath(string refPath, string targetPath) {
string[] parts1=Path.GetFullPath(refPath).Split('\\');
string[] parts2=Path.GetFullPath(targetPath).Split('\\');
int i=0;
for (; i<parts1.Length && i<parts2.Length; i++) {
if (string.Compare(parts1[i], parts2[i])!=0) break;
}
string result="";
for (int j=i; j<parts1.Length; j++) result+="..\\";
result+=string.Join('\\', i, parts2.Length-i);
return result;
}
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You can do this with some P/Invoke code:
public const int MAX_PATH = 260;
public const uint FILE_ATTRIBUTE_DIRECTORY = 0x10;
internal const string SHLWAPI = "shlwapi.dll";
[DllImport(SHLWAPI, CharSet = CharSet.Unicode)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool PathRelativePathTo([MarshalAsAttribute(UnmanagedType.LPWStr)] StringBuilder pszPath, [MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszFrom, uint dwAttrFrom, [MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszTo, uint dwAttrTo);
[DllImport(SHLWAPI, CharSet = CharSet.Unicode)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool PathIsDirectoryEmpty([MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszPath);
public static string PathRelativePathTo(string from, string to)
{
string result = String.Empty;
StringBuilder path = new StringBuilder(MAX_PATH);
uint fromAttributes = IsDirectory(from) ? FILE_ATTRIBUTE_DIRECTORY : 0;
uint toAttributes = IsDirectory(to) ? FILE_ATTRIBUTE_DIRECTORY : 0;
if (PathRelativePathTo(path, from, fromAttributes, to, toAttributes))
{
result = path.ToString();
}
return result;
}
public static bool IsDirectory(string path)
{
return PathIsDirectory(path);
}
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
modified on Thursday, August 13, 2009 7:49 PM
|
|
|
|
|
Thanks Scott. I'll add it to my toolbox.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You're welcome.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Marc, see my reply to Luc here[^] which gives you the P/Invoke code necessary to call the PathRelativePathTo function from shlwapi.dll. This should give you what you are after.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Hi ,
I have 2 buttons on the form, SAVE and PRINT .. I want the user to click on the SAVE button first to save the current record and then print it. Now.. my question is.... if the user clicks first on the PRINT button before clicking on the SAVE button.....I want to alert the user using MessageBox etc.... upon click..that the record needs to be save first(by clicking on the save button) etc... how can i achive this....
(I have done the enable and disable operations by it was not accepted by the client .... ie on from_load ,,, disable print and enable save ....and on save_click enable print)
thanks,
|
|
|
|
|
I think you must implement something like isDirty variable.
That means, if the user change something, you must set isDirty=true.
if(isDirty)
{
MessageBox.Show("Please save first");
}
else
{
}
|
|
|
|
|
OKay thanks, it did the trick !!
|
|
|
|
|
I have device running Windows CE 5.0.
I am developing an application for it in C# using a SQL server mobile database.
In order to install the database on the device,I first have to add SQLserverCE.dll.But I don't know why the folder or dll is not available. I tried to install Microsoft SQL Server Mobile Developer Tools.but still nothing.
I also reinstalled SQl Server 2005...
|
|
|
|
|
Hi
I m very fresh guy for developement field. Actually I need to edit a opendocument spreadsheet.ods file. In c# I could not add a namespace for that, like
using Excel = Microsoft.Office.Interop.Excel
for this what are the settings to be made, i m having visual studio 2005.
Please let me know about it.
Thanks
Sath.
|
|
|
|
|
Have you added a reference to that assembly?
|
|
|
|
|
Hi
In my system Excel has been uninstalled, I have only openoffice. I can't find any Excel related dll to add reference. Could you please tell the corresponding dll for Openoffice.
Thanks
sath.
|
|
|
|
|
|
This won't allow the OP to open opendocument format files.
ODS formats are xml files and so no need to add namespaces for them nor reference any dlls - but will have to use the XML stuff in C#.
Here's a link that may help: http://www.codeguru.com/csharp/csharp/cs_data/xml/article.php/c16311/[^]
Don't know how good it is - got by googling 'opendocument c# .ods'.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hey!
I´m looking for a code that i can see the monitor from an other Pc on my network(how teamviewer). I have a Server and Client i can write something to him and i can send him files and now i will see the monitor when there is a change.
|
|
|
|
|