Click here to Skip to main content
15,893,564 members
Home / Discussions / C#
   

C#

 
GeneralRe: Questions about inheritance Pin
mtbikerj27-Aug-09 7:22
mtbikerj27-Aug-09 7:22 
AnswerRe: Questions about inheritance Pin
PIEBALDconsult13-Aug-09 14:18
mvePIEBALDconsult13-Aug-09 14:18 
QuestionDatagrid print location help Pin
spankyleo12313-Aug-09 9:28
spankyleo12313-Aug-09 9:28 
AnswerRe: Datagrid print location help [REPOST attempt to bump] Pin
Henry Minute13-Aug-09 9:45
Henry Minute13-Aug-09 9:45 
GeneralRe: Datagrid print location help [REPOST attempt to bump] Pin
spankyleo12313-Aug-09 10:10
spankyleo12313-Aug-09 10:10 
GeneralRe: Datagrid print location help [REPOST attempt to bump] Pin
0x3c013-Aug-09 10:13
0x3c013-Aug-09 10:13 
GeneralRe: Datagrid print location help [REPOST attempt to bump] Pin
spankyleo12313-Aug-09 10:18
spankyleo12313-Aug-09 10:18 
QuestionI am having issues with pictures and sql server can someone help me understand what is going on. [modified] Pin
JollyMansArt13-Aug-09 6:36
JollyMansArt13-Aug-09 6:36 
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();
               //specify your own initial directory

               if (lbxAssistSuiteUserList.SelectedIndex > -1)
               {
                   try
                   {
                       fldlg.InitialDirectory = @":C\";
                       //this will allow only those\ file extensions to be added
                       fldlg.Filter = "Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif|(*.gif)|*.gif|(*.jpg)|*.jpg|(*.jpeg)|*.jpeg|(*.bmp)|*.bmp|(*.wmf)|*.wmf|(*.png)|*.png";
                       //fldlg.ShowDialog();
                       if (fldlg.ShowDialog() == DialogResult.OK)
                       {
                           imagename  = fldlg.FileName;
                           Bitmap newimg = new Bitmap(imagename);
                           pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
                           pictureBox3.Image =(Image)newimg;
                           //pictureBox3.Image = System.Drawing.Image.FromFile(openFileDialog1.FileName);
                           pictureBox3.Refresh();

                           //Update the SQL Tables.
                           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;
       //use filestream object to read the image.
       //read to the full length of image to a byte array.
       //add this byte as an oracle parameter and insert it into database.

           try
           {
               //proceed only when the image has a valid path
               if (imagename != "")
               {
               FileStream fs;
               fs = new FileStream(@imagename, FileMode.Open, FileAccess.Read);

               //a byte array to read the image
               byte[] picbyte = new byte[fs.Length];
               fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
               fs.Close();

               //open the database using odp.net and insert the data
               string connstr = WhatIsMyConnectionString;
               SqlConnection conn = new SqlConnection(connstr);
               conn.Open();

               string query;
               //Find the index
               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(" +
                       //UserIndex.ToString() + "," + " @pic)";
                       query = "insert into tblApplicationUsersPic(id_image,pic) values(@i, @p)";

                   }
                   else
                   {
                       UserIndex = Convert.ToInt32(((DomainUsersClass)ApplicationUsersArray[i]).Index);
                       //query = "update tblApplicationUsersPic set pic = @pic where id_image = '" + UserIndex.ToString() + "' ";
                       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;
               }

               //sqlCon.Open();

               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() + "' ");
                   //UserIndex = Convert.ToInt32(((DomainUsersClass)ApplicationUsersArray[i]).Index);

               }

               /*
               SqlParameter picparameter = new SqlParameter();
               picparameter.SqlDbType = SqlDbType.Image;
               picparameter.ParameterName = "pic";
               picparameter.Value = picbyte;
               SqlCommand cmd = new SqlCommand(query, conn);
               cmd.Parameters.Add(picparameter);
               cmd.ExecuteNonQuery();

               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() + "' ");
                   //UserIndex = Convert.ToInt32(((DomainUsersClass)ApplicationUsersArray[i]).Index);

               }
               MessageBox.Show("Image Added");
               cmd.Dispose();
               conn.Close();
               conn.Dispose();
               //Connection();
               */
               }


           }
           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

AnswerRe: I am having issues with pictures and sql server can someone help me understand what is going on. Pin
Luc Pattyn13-Aug-09 6:49
sitebuilderLuc Pattyn13-Aug-09 6:49 
GeneralRe: I am having issues with pictures and sql server can someone help me understand what is going on. Pin
JollyMansArt13-Aug-09 6:55
JollyMansArt13-Aug-09 6:55 
GeneralRe: I am having issues with pictures and sql server can someone help me understand what is going on. Pin
Luc Pattyn13-Aug-09 7:05
sitebuilderLuc Pattyn13-Aug-09 7:05 
GeneralRe: I am having issues with pictures and sql server can someone help me understand what is going on. [modified] Pin
JollyMansArt13-Aug-09 7:27
JollyMansArt13-Aug-09 7:27 
AnswerRe: I am having issues with pictures and sql server can someone help me understand what is going on. Pin
Henry Minute13-Aug-09 7:20
Henry Minute13-Aug-09 7:20 
GeneralRe: I am having issues with pictures and sql server can someone help me understand what is going on. Pin
JollyMansArt13-Aug-09 8:29
JollyMansArt13-Aug-09 8:29 
GeneralRe: I am having issues with pictures and sql server can someone help me understand what is going on. Pin
Henry Minute13-Aug-09 8:38
Henry Minute13-Aug-09 8:38 
AnswerRe: I am having issues with pictures and sql server can someone help me understand what is going on. Pin
JollyMansArt13-Aug-09 7:44
JollyMansArt13-Aug-09 7:44 
GeneralRe: I am having issues with pictures and sql server can someone help me understand what is going on. Pin
Luc Pattyn13-Aug-09 8:34
sitebuilderLuc Pattyn13-Aug-09 8:34 
QuestionActive X Control... Pin
priyareguri13-Aug-09 6:00
priyareguri13-Aug-09 6:00 
AnswerRe: Active X Control... Pin
Dave Kreskowiak13-Aug-09 7:12
mveDave Kreskowiak13-Aug-09 7:12 
GeneralRe: Active X Control... Pin
priyareguri18-Aug-09 3:21
priyareguri18-Aug-09 3:21 
QuestionGetRelativePath implementation ? Pin
Marc Clifton13-Aug-09 5:54
mvaMarc Clifton13-Aug-09 5:54 
AnswerRe: GetRelativePath implementation ? Pin
Luc Pattyn13-Aug-09 6:52
sitebuilderLuc Pattyn13-Aug-09 6:52 
GeneralRe: GetRelativePath implementation ? Pin
Marc Clifton13-Aug-09 9:18
mvaMarc Clifton13-Aug-09 9:18 
GeneralRe: GetRelativePath implementation ? Pin
Luc Pattyn13-Aug-09 9:48
sitebuilderLuc Pattyn13-Aug-09 9:48 
GeneralRe: GetRelativePath implementation ? [modified] Pin
Scott Dorman13-Aug-09 10:36
professionalScott Dorman13-Aug-09 10:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.