|
thanks for the info mate....will be carefull..
|
|
|
|
|
1) The issue I am currently having is when I add the image to the sql table the it ends up giving me a exception saying "invalid parameter".
What did I do to mess this up? UpdateData() is the process of the 3 that is where the exception is comming from directly after it does update or insert the table.
2) Also if it would not be to much trouble I need help in 2 other aspects. Now that the image is at the sql table I need to be able to retrieve it directly into a picture box. There is no need to recreate the file. I have some theories but I do not know the correct way of doing this.
3) Lastly If I could get some understanding of how to access the sql server in the below method. Some if it does not make since to me to build a sql string with the parameters, then call the parameters later on in code up to update. My current methodoligy is to just build the sql string the way I want it as I go, because I can not make much since on how sql parameters work.
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()
{
bool FoundMe = false;
int UserIndex = -1;
try
{
if (imagename != "")
{
FileStream fs;
fs = new FileStream(@imagename, FileMode.Open, FileAccess.Read);
byte[] picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
string connstr = WhatIsMyConnectionString;
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string query;
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);
query = "insert into tblApplicationUsersPic(id_image,pic) values(@i, @p)";
}
else
{
UserIndex = Convert.ToInt32(((DomainUsersClass)ApplicationUsersArray[i]).Index);
query = "update tblApplicationUsersPic set pic = @p where id_image = @i";
}
}
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;
}
SqlCommand sc = new SqlCommand(query, conn);
sc.Parameters.AddWithValue("@i", UserIndex.ToString());
sc.Parameters.ty
sc.Parameters.AddWithValue("@p", picbyte);
sc.ExecuteNonQuery();
sc.Dispose();
conn.Close();
conn.Dispose();
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);
}
}
modified on Thursday, August 13, 2009 1:25 PM
|
|
|
|
|
please edit your message and surround your code with PRE tags. No one is going to read it as is.
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.
|
|
|
|
|
|
No that did not help, as you can see for yourself.
What you need is:
- no CODE tags
- PRE tags
and take care about the checkboxes below the edit box: one should NOT ignore HTML
The result could be like this:
this represents some code in PRE tags
that gets formatted, syntax colored, and
hence is readable, yielding more and better replies.
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.
|
|
|
|
|
There I think I figured it out? now it is showing in the code block.
Any Ideas what I am doing wrong. It keeps giving me a error "Invalid parameter"
modified on Thursday, August 13, 2009 1:33 PM
|
|
|
|
|
I cannot help with your main question but as far as loading the image into a picturebox, I have two suggestions.
1) I googled c# dbpicturebox and the first two hits seem extremely relevant.
2) Extending the TreeView[^] on MSDN. The code download for this article contains a DbPictureBox Control, which you may be able to adapt.
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.”
|
|
|
|
|
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 !!
|
|
|
|
|