Quantcast
Channel: Visual C# forum
Viewing all 31927 articles
Browse latest View live
↧

Adding data from Combo Boxes to a List View Object

$
0
0

Hello, I've got an issue with getting data selected from separate combo boxes into a list view box. I had already done this in VB so I thought I could use a VB to C# code converter, but this doesn't work, and I've just started in this language. What I have at the moment which I know is wrong is - (The "lsvstarter" is the list view box, "cmbStarter" is first combo box, "cmbStrQuantity" is the second combo box that has an effect on the data shown on the third column of the list view box.

// add each chosen item, its qty and subtotal to the listview box

                lsvstarter.Items.Add(cmbStarter.Text);

                lsvstarter.Items.Add(

"index1").SubItems.Add(cmbStrQuantity.Text);

                lsvstarter.Items.Add(

"index1").SubItems.Add(Startertotal);

                index1 = (index1 + 1);

                sngstartertotal = 0;       

foreach(ListViewItemxinlsvstarter.Items)

                {

                    sngstartertotal = (sngstartertotal + x.SubItems(2).Text);

                }         

↧

How to read my information from a html file?

$
0
0

Hi

I saved an html file from a website.

How can I read my information (For example the first URL) from the html file?

following code reads line by line:

            using (StreamReader reader = new StreamReader(Application.StartupPath + @"\x.htm"))
            {
                String line = String.Empty;
                while ((line = reader.ReadLine()) != null)
                {
                    MessageBox.Show(line);
                }
            }

↧
↧

excel stays live as a process when terminating a program during debug

$
0
0

Hi

In my C# windows application I open an excel file with

Excel.Application xlApp = new Excel.ApplicationClass();

when in debug mode in VS I often stop the application mid process by clicking on "stop debugging" in the VS menu. I noticed that this seems to leave many opened
EXCEL.EXE *32 processes (I see them in task manager)

This eventually clogs my computer.

I assume it is because the application never reached the

xlApp.Quit();

which I have when the application is in ordinary mode.

What can I do about it so that I would not have all these processes staying alive after I stopped the program midway in debug?

↧

Difference between Datahiding and Abstraction - OOPS

$
0
0

Hi,

I got stuck in finding the exact difference in these two.

1. Datahiding is achieved through the access specifiers or by using it inside the function or also by using it inside the class.

2. Abstraction means showing the necessary details and hiding the necessary details.

If the above definition for the abstraction is correct then datahiding and abstraction become similar, correct.?

Could u guys help me to clarify with example.

Thanks in advance.


NANDAKUMAR.T

↧

FileInfo.CopyTo Size Restrictions

$
0
0

Are there file size restrictions in using the FileInfo.CopyTo function?

I have a Service which sorts files around on a machine and I tend to see failures in very large file sizes.  The routine moves files from one array to another.  If I open File Explorer and copy the file manually I do not get an error.

The Event log under System will show a message:

{Delayed Write Failed} Windows was unable to save all the data for the file.  The data has been lost.  This error may be caused by a failure of your computer hardware or network connection.  Source Ntfs.  Category None

Followed by:

Application popup Windows - Delayed Write Failed.  Windows was unable to save all data for the file xxxxxx.  The data has been lost.  Source Application popup.  Category None.

The file today is about 50GB in size and is moving from one SAS array to another.  I only get these failures in very large files (larger than 5GB) and of course it is not consistent.  The files alway work fine in file explorer which would lead me to believe that it is not a hardware issue.

So to make the question simple, is there a time-out period in the CopyTo routine that would cause it to decide that the copy has failed prematurely?  Is there a better routine I should be using to move the files around on the system?

I'm not seeing an exception being logged by the Service under Application during this time.

I appreciate any information on this topic.

Thanks,

Mike



↧
↧

How to specify a wild card in the WHERE clause of a table adapter query (defined in the table adapter) in C#

$
0
0

I have already read a similar post here, but it did not answer my question.

I am calling a query directly from a C# program. The query I am calling already exists in the table adapter. Here is the query:

SELECT     owner_name_1

FROM BuildingPermit.dbo.real_estate

WHERE (prop_addr_no LIKE ?) AND (prop_addr_str = ?)

If I enter '11%' and 'ACADEMY ST' I get a non-null result.

If I use MSQL Server Management Studio and execute the same query on the same database, I get a non-null result.

Here is the C# code that does not work:

        private void owner_cb_DropDown(object sender, EventArgs e)
        {
            string str_no = street_number_cb.Text.Trim().ToUpper() + "%";
            string str_name = street_name_cb.Text.ToUpper();

            string owner_name_1 = (string ) (real_estateTableAdapter1.owner_name_1_q(str_no, str_name));
            owner_cb.Text = owner_name_1;
        }

owner_name_1 comes back null. I'm trying to figure out what I am doing wrong. I've tried to put @p1 and @p2 in the table adapter query, but that won't parse. The Query Designer doesn't like the @.




↧

mixing default and custom serialization within a class inheritance tree

$
0
0

I have a hierarchy of classes in C# related through inheritance.  I'd like to implement custom serialization (meaning implement the ISerializable interface, GetObjectData() method, and de-serialization constructor) for one of them in the hierarchy. I'm looking for guidance on how to do this and what the effects of this would be on the other classes in the hierarchy.

Imagine, for example, something like the below.

Shape
|
|
Circle
|
|
FilledCircle

In the above, Shape is a base class, Circle is derived from Shape, and FilledCircle is derived from Circle.  Initially they all have just the [Serializable] attribute and use default serialization.  I'd like to customize the serialization for just one of the classes.  It could be any one of them.  Also, for the sake of discussion, assume at runtime I'm only working with FilledCircle objects - the most derived class.

Given that I implement custom serialization on one of those classes how are the others affected?  I've done some experimentation with this and it seems if I implement custom serialization on Circle then I'm obligated to do so on FilledCircle as well or I wont' be able to load FilledCircle (I get an exception since the custom serialization constructor isn't defined for FilledCircle).

It also seems that if I implement custom serialization in FilledCircle, I must also do it in the base class(es) and call them from the derived class or else they won't get serialized.

What's the trick to best handling this?  Does deciding to do custom serialization on one of the classes effectively force all other classes above/below it to do so also?  Is it not possible to do custom serialization on just one class in a hierarchy and tell C# to do default serialization for the other classes?

↧

key cannot be null. parameter name key c#

$
0
0

i keep having this error message anytime i want to add report viewer to Gizmox webgui form

key cannot be null. parameter name key

↧

Changing The Environment.SpecialFolder.CommonApplicationData Value

$
0
0

I have a client that is currently running our software which uses the Environment.SpecialFolder.CommonApplicationData variable in C# as the base location to save all our config/data files.

So, for example, the path is Environment.SpecialFolder.CommonApplicationData\\Company Name\\Product\\ or "C:\ProgramData\Company Name\\Product\\"

is there a way to change this system variable so that it points to another location?  The idea is that I can move the data files for C:\ProgramData to another drive, like "D:\ProgramData"

I hope that makes sense.

Thanks,

Bryan

↧
↧

How can I have the date come up on a program as the day, ie '02/01/2015' shows as 'Tuesday'??

$
0
0
Any help will be much appreciated, i'm very new to c# so trying to learn as quickly as possible.
↧

BackgroundWorker starting again in Completed event

$
0
0

I want a background worker to continue running and occasionally update the user interface. My first idea was to use a BackgroundWorker and in its completed event just fire it up again.

Is using a BackgroundWorker in this fashion acceptable? Or are there potential issues from using the completed event to trigger the worker?


Below is some Pseudo code of what my intentions are

classProgram{privatestaticBackgroundWorker worker;privatestaticInt32 runs =0;staticvoidMain(string[] args){
        worker =newBackgroundWorker();
        worker.DoWork+= worker_DoWork;
        worker.RunWorkerCompleted+= worker_RunWorkerCompleted;
        worker.RunWorkerAsync(runs);Console.ReadLine();}staticvoid worker_DoWork(object sender,DoWorkEventArgs e){//Do time consuming workThread.Sleep(3000);}staticvoid worker_RunWorkerCompleted(object sender,RunWorkerCompletedEventArgs e){//Update the UI and start time consuming work again
        runs++;Console.WriteLine("Completed run #"+ runs);
        worker.RunWorkerAsync();}}
↧

Multiple choice question

$
0
0

I'm doing a course in C # and there is a multiple choice question:

The question is this:

Which of the following statements are FALSE:

a: An interface is a named collection of method definitions, without implementations

b: In an interface, all method declarations are left blank

c: The class that is inheriting from an interface must implement all the methods

d: The implementing class cannot implement new classes of its own

They say that the answer is C:, but I don't think that's the right answer, I thought you should implement al methods from an interface or else you get an error?

What do you thing of this question ?

↧

About Executing Powershell CMDLET using C#

$
0
0

We are using the Powershell object to retrieve the GetMailbox from Exchange Server 2013 and we got the result but we want to retrieve all properties i.e in Format List or Format Table. I can't able to do this.

Here is the Code. Thanks in advance.

 public Collection<PSObject> GetUsersUsingBasicAuth(string liveIDConnectionUri, string schemaUri, PSCredential credentials, int count)
        {
            WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(liveIDConnectionUri), schemaUri, credentials);
            connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;

         

            using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
            {
               
                strCommand = "Get-mailbox";
                count = 100;
                return GetUserInformation(count, runspace, strCommand);
            }
        }

 public Collection<PSObject> GetUserInformation(int count, Runspace runspace, string commands)
        {
            using (PowerShell powershell = PowerShell.Create())
            {
                // powershell.AddScript(commands);




                powershell.AddCommand(commands);
                powershell.AddParameter("ResultSize", count);
                powershell.AddParameter("Filter", "Displayname -like 'Testuser'");

            


                runspace.Open();

                powershell.Runspace = runspace;

                return powershell.Invoke();



            }
        }

        protected void ExecuteCommand_Click(object sender, EventArgs e)
        {
          

            string user, pass;
            user = Session["Username"].ToString();
            pass = Session["Password"].ToString();
            var secure = new SecureString();
            string password = pass;
            foreach (char c in password)
            {
                secure.AppendChar(c);
            }
            
            PSCredential obj = new PSCredential(user, secure);
            Collection<PSObject> results = GetUsersUsingBasicAuth(SHELL_URI, "http://schemas.microsoft.com/powershell/Microsoft.Exchange", obj, 15);
            result = new List<string>();
            for (int i = 0; i < results.Count; i++)
            {

                result.Add(results[i].ToString());
            }

            
            gv.DataSource = result;
            gv.DataBind();
            
            

        }

↧
↧

Is there a design pattern for splitting up files into smaller files?

$
0
0

I am developing a project where I have to load very large files (upto 50 MB). Currently I am loading these files completely into (consecutive) memory. This has the advantage that I can very easily change bytes at certain locations, because I do not know the structure of all bytes.

However, my intention is to also change the structure, e.g. removing/adding 'chunks'. Now I have the idea to remove the 'known' parts out of it, store them in classes with a data chunk only containing those parts and make a sort of reference list to those chunks.

E.g.:

Original file:

  • Header
  • ChunkA 1
  • ChunkA 2
  • Intermediate
  • ChunkB 1
  • Footer

The result will be:

ChunkA 1 and ChunkA 2 instance. ChunkB 1 instance

'File' instance and a reference with base offsets + reference to all chunks.

At the end I have to 'recreate' or write the original file (with changes) back.

Is this in general a good idea or is there some design pattern helping me in this?

↧

What is pdh in C# app process dump?

$
0
0

Hi,

I ran DebugDiag on a process dump of a C# app (targeted at .NET 3.5)

One of the native heaps is 1/2 Gb in size and says it is used by 'pdh' - a dump of the memory there looks like performance counters. Does this indicate the heap is injected by Perfmon somehow? This app is blowing up on site with Out of Memory exceptions so if someone could nudge me in the right direction I'd be grateful.

If I have the wrong forum, my apologies, please tell me where to move my query and I will do so.

Many Thanks,

Adam.
============


Heap 21 -                   0x096d0000

Heap Name  pdh!hPdhHeap
Heap Description  This heap is used by pdh
Reserved memory  566.1                         MBytes
Committed memory  543.89                         MBytes(96.08% of reserved)
Uncommitted memory  22.21                         MBytes(3.92% of reserved)
Number of heap segments  39 segments
Number of uncommitted ranges  39 range(s)
Size of largest uncommitted range  0                     Bytes
Calculated heap fragmentationUnavailable


Segment Information
Base AddressReserved SizeCommitted SizeUncommitted SizeNumber of uncommitted rangesLargest uncommitted blockCalculated heap fragmentation
0x096d0000256 KBytes256 KBytes0 Bytes10 Bytes0%0
0x0c8a00001024 KBytes1024 KBytes0 Bytes10 Bytes0%0
0x0db500002 MBytes1.88 MBytes124 KBytes1124 KBytes-1%Unavailable
0x0dd500004 MBytes3.88 MBytes124 KBytes1124 KBytes-1%Unavailable
0x0e1500008 MBytes7.88 MBytes124 KBytes1124 KBytes-1%Unavailable
0x0e95000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x108e000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x118b000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1288000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1385000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1482000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x157f000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x167c000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1779000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1876000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1973000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1a70000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1b6d000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1c6a000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1d67000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1e64000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x1f61000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x205e000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x215b000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2258000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2355000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2452000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x254f000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x264c000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2749000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2846000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2943000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2a40000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2b3d000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2c3a000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2d37000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2e34000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x2f31000015.81 MBytes15.75 MBytes60 KBytes160 KBytes-1%Unavailable
0x302e000015.81 MBytes7 MBytes8.81 MBytes18.81 MBytes-1%Unavailable

↧

Error while inserting information along with images into database..

$
0
0

This is my User Interface:

This is My Error Page:

This is code which I've written under Add customer Info button Method:

private void btnaddinfo_Click(object sender, EventArgs e)
        {
            string scn = ConfigurationManager.ConnectionStrings["Myconn"].ConnectionString;
            using (SqlConnection cn = new SqlConnection(scn))
            {
                using (SqlCommand cmd = new SqlCommand("SP_Info", cn))
                {
                    try
                    {
                        byte[] img = null;
                        FileStream fs = new FileStream(imageloc, FileMode.Open, FileAccess.Read);
                        BinaryReader br = new BinaryReader(fs);
                        img = br.ReadBytes((int)fs.Length);

                        cmd.CommandType = CommandType.StoredProcedure;
                        if (cn.State != ConnectionState.Open)
                            cn.Open();

                        SqlParameter p1 = new SqlParameter("@Hp_Number", SqlDbType.NVarChar, 50);
                        SqlParameter p2 = new SqlParameter("@Customer_Name", SqlDbType.VarChar, 50);
                        SqlParameter p3 = new SqlParameter("@Customer_Contact_Number", SqlDbType.NVarChar, 15);
                        SqlParameter p4 = new SqlParameter("@Guarantor_Name", SqlDbType.VarChar, 50);
                        SqlParameter p5 = new SqlParameter("@Guarantor_Contact_Number", SqlDbType.NVarChar, 15);
                        SqlParameter p6 = new SqlParameter("@Hp_Date", SqlDbType.Date);
                        SqlParameter p7 = new SqlParameter("@Customer_Address", SqlDbType.NVarChar, Max);
                        SqlParameter p8 = new SqlParameter("@Vehicle", SqlDbType.VarChar, 50);
                        SqlParameter p9 = new SqlParameter("@Vehicle_Model", SqlDbType.VarChar, 50);
                        SqlParameter p10 = new SqlParameter("@Vehicle_Number", SqlDbType.NVarChar, 50);
                        SqlParameter p11 = new SqlParameter("@Chasis_Number", SqlDbType.NVarChar, 50);
                        SqlParameter p12 = new SqlParameter("@Engine_Number", SqlDbType.NVarChar, 50);
                        SqlParameter p13 = new SqlParameter("@FC_Date", SqlDbType.Date);
                        SqlParameter p14 = new SqlParameter("@Insurance_Date", SqlDbType.Date);
                        SqlParameter p15 = new SqlParameter("@Insurance_Amount", SqlDbType.Int);
                        SqlParameter p16 = new SqlParameter("@Paid_Amount", SqlDbType.Int);
                        SqlParameter p17 = new SqlParameter("@Vehicle_Pic", Image);
                        SqlParameter p18 = new SqlParameter("@Customer_Pic ", Image);
                        SqlParameter p19 = new SqlParameter("@Guarantor_Pic ", Image);
                        SqlParameter p20 = new SqlParameter("@Documents_Pic", Image);
                        SqlParameter p21 = new SqlParameter("@Insurance_Pic", Image);

                        p1.Value = tbhpnum.Text;
                        p2.Value = tbcusnam.Text;
                        p3.Value = tbcusmblno.Text;
                        p4.Value = tbguanam.Text;
                        p5.Value = tbguamblno.Text;
                        p6.Value = tbhpdat.Text;
                        p7.Value = tbcusadd.Text;
                        p8.Value = tbveh.SelectedItem;
                        p9.Value = tbvehmod.SelectedItem;
                        p10.Value = tbvehnum.Text;
                        p11.Value = tbchanum.Text;
                        p12.Value = tbengnum.Text;
                        p13.Value=tbfcdat.Text;
                        p14.Value=tbinsdat.Text;
                        p15.Value = Convert.ToInt32(tbinsamt.Text);
                        p16.Value=Convert.ToInt32(tbpaiamt.Text);
                        p17.Value = boxvehpic.Image;
                        p18.Value=boxcuspic.Image;
                        p19.Value=boxguapic.Image;
                        p20.Value=boxdocpic.Image;
                        p21.Value=boxinspic.Image;


                        cmd.Parameters.Add(p1);
                        cmd.Parameters.Add(p2);
                        cmd.Parameters.Add(p3);
                        cmd.Parameters.Add(p4);
                        cmd.Parameters.Add(p5);
                        cmd.Parameters.Add(p6);
                        cmd.Parameters.Add(p7);
                        cmd.Parameters.Add(p8);
                        cmd.Parameters.Add(p9);
                        cmd.Parameters.Add(p10);
                        cmd.Parameters.Add(p11);
                        cmd.Parameters.Add(p12);
                        cmd.Parameters.Add(p13);
                        cmd.Parameters.Add(p14);
                        cmd.Parameters.Add(p15);
                        cmd.Parameters.Add(p16);
                        cmd.Parameters.Add(p17);
                        cmd.Parameters.Add(p18);
                        cmd.Parameters.Add(p19);
                        cmd.Parameters.Add(p20);
                        cmd.Parameters.Add(p21);

                        int count = cmd.ExecuteNonQuery();
                        if (count == 1)
                        {
                            MessageBox.Show(count.ToString()+ "Record(s) Saved.");
                        }
                        else
                        {
                            MessageBox.Show("Please correct the error which you have entered and then click on addinformation button");
                        }
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show(ex.ToString());

                    }
                    finally
                    {
                        if (cn.State == ConnectionState.Open)
                            cn.Close();
                    }
                }
            }
        }

Whats wrong on my code......


Thanks & Regards RAJENDRAN M

↧

Timer Help w/ Button

$
0
0
I want to have a button that when clicked, activates a progress bar. once the progress bar is done, go to Form2.cs
↧
↧

Connecting to a SQL database on my website.

$
0
0

Hello,

I'm trying to create a login form that connects to a SQL database that's placed on my website. My problem is that I don't know how to connect to the database. Let's take these for an example:

Server the database is on: 10.246.16.159:3306

Database name: rhythmcheaters_

Database section: phpbb_users

Database password : 1A2b3C4d




↧

missing code...

$
0
0

hey guys i started this code to validate pass and also block attemps.Works but will not count retry?i know im missing a loop back to start but don't know how...

[code]

               

int attempts = 3;
            System.IO.StreamReader reader = new System.IO.StreamReader("auth.txt");

            String text = reader.ReadToEnd();

            if (!System.Text.RegularExpressions.Regex.IsMatch(text, textBox1Search.Text) && attempts > 0)

            {
            attempts --;
            textBox2Message.Text = "Erreur de Nip,Essayer encore" + attempts + " attempts left";


            }
            else if (!System.Text.RegularExpressions.Regex.IsMatch(text, textBox1Search.Text) && attempts == 0)
            {
            textBox2Message.Text = "Wrong password! your account has been blocked";

            }
            else
            {
            this.Hide();
            var main = new Main();
            main.Show();

[/code]

↧

ITaskFolder.GetTasks(0) giving run times after conversion to local timezone

$
0
0

Hi All,

I am trying to retrieve the scheduled tasks from a specific folder from a remote machine (Its timezone is different from that of my machine) by connecting to it with credentials through the following C# code.

ITaskFolder root = schedulerRunning.GetFolder("\\XYZ");
IRegisteredTaskCollection scheduledTasks = root.GetTasks(0);
foreach (IRegisteredTask item in scheduledTasks) { ------ }

My machine's timezone is UTC+05:30. Remote machine's timezone is: UTC-08:00

Suppose that the actual next run time shown in the task scheduler of that remote machine is : 11/30/2011 04:00:00 AM.

For onetime trigger task: 

The above code on my machine shows 12/30/1899 12:00:00 AM.

For multiple triggers (Daily, weekly, monthly ...) task:

The above code on my machine shows 12/31/2011 04:00:00 AM.

 

What's problem with this code? Why is it converting the actual time to my local time? If the converted time is already passed no my machine, it will give me a default date 12/30/1899 12:00:00 AM. 

Please help me if anyone has a solution to this issue.

 

Thanks,

Sai

↧
Viewing all 31927 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>