|
vijaylumar wrote: i am doing a setup of a Project developed in c#
The question here is - what do you mean by "doing a setup"? Are you using a setup program or writing code to build an installer? Which OS are you targeting? If you're using an installer, there's nothing more that you need to worry about, because an "installation" can be done only by an administrator.
If you're writing it yourself, it's a matter of mentioning it in your project's manifest file that it needs administrative privileges. (line of interest would be level="requireAdministrator" under requestedExecutionLevel , if I remember it right... can't pull it off now, not on a dev machine. Just google if doubtful).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
hi
i m doing setup using .net ide i.e Setup and Deployment Project Type
|
|
|
|
|
hello, I have an usual problem ( a least for me ), where I created multiple objects (say b1, b2, b3 ,b4 ) from the same class (b) inside another class (class a), the object is a1.
The variable for class b such as "value" is changed for every object, for example
a1.b1.value = 10;
also a1.b2.value = 20;
..
..
..
now when the value of 20 is entered in b2 the value in b1 is also changed to 20.
Did anyone see this problem earlier?
thanks
|
|
|
|
|
Hi,
show actual code (in PRE tags!) and someone will explain to you what happened.
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.
|
|
|
|
|
At a guess, it sounds like when you create your objects you are ending up with them all pointing to the same reference but without code it's hard to explain what is happening.
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
|
|
|
|
|
sounds like u did a code by using reference type.. so that it copied 20 to another object also..But we need to examine the code
sureshkumar.S
|
|
|
|
|
Hi everyone,
I'm very new to programming and have run into a snag that I can't seem to figure out.
I have some pretty simple classes for a grading program. I have four classes (Course, Student, Assignment, StudentAssignment) StudentAssignment inherits from Assignment and adds a grade and notes.
Course has a list<assignment>
Student has a list<course> and a list<studentassignment>
When I add a course to Student list<course> I use the constructor for StudentAssignment to add a studentAssignment for every assignment in list<course>
Now, I need to keep the two in sync. What is the best way to do this. I tried foreach loops but since I can't downcast Assignment to StudentAssignment it's tough to compare the two.
I know there's probably a million ways to do it. Can anyone help?
|
|
|
|
|
Without seeing at least the basics of what you have setup it's difficult. What do you mean "keep the two in sync"? Which "two" are you referring to?
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
|
|
|
|
|
my original post didn't work right.
It should say course has a List<<Assignment>>
Student has a List<Course> and a List<StudentAssignment>
Since the student takes a course, all the assignments from that course should be in their Student assignment list.
The two things I need to keep in sync are the Assignment list from the course and the assignment list for the student. When I add or delete an assignment from the course assignment list, it needs to be added or deleted in the student assignment list also. If I delete a course from the student course list, I need to delete all assignments related to that course from the student list also. That's what I mean by "keep the two in sync"
|
|
|
|
|
Again Sorry.
Course has a List<Assignment>
|
|
|
|
|
Ok...that makes a bit more sense. There are several possibilities to accomplish this.
One option is to derive concrete collections for your course list and assignment list (CourseList : List<Course> and AssignmentList : List<StudentAssignment> ) and in those concrete collections override the Add/Insert/etc. methods to raise events that your other classes can then respond to and ensure that they update their appropriate fields.
A similar option would be to derive from BindingList<T>, where T is Course and StudentAssignment, and have your other classes respond to the ListChanged event.
Yet another option is to simply use List<T> like you have and either provide your own methods to do the Add/Insert/etc. and when you take an action on one list be sure that you take the appropriate action on the other list at the same time.
There are probably other ways to achieve this, but these are the ones I can think of off-hand. Each has benefits and drawbacks and one is not necessarily any better than another.
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
|
|
|
|
|
Thanks Scott, this was very helpful.
I'm now using WPF and ObservableCollection for ease of binding. I slightly modified your third suggestion and added a "Synchronizer" class and call it's add / modify / remove methods every time I add / remove / or modify any of the lists. Thanks again for the help.
|
|
|
|
|
First off, I'm guessing you didn't escape some angle-brackets (<>) in your post.
|
|
|
|
|
|
You asked this less than 12 hours ago! You should have continued on your original thread.
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.”
|
|
|
|
|
ohh ooops....i couldnt find it so just thought would ask a new one..
Cheers!!
|
|
|
|
|
If you go to your profile page and click on Messages Posted you can get a list of direct links to your past 200 messages
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
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());
}
}
}
|
|
|
|
|