C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

Share tech news, updates, or what's on your mind.

Sign up to Post

I have in my c# application a 3 step process under a button click  (see below the 3 steps)

3 different method called under this button
Step 1 Calls a method That  prepares a list placing the output in a list called "results" (see script below and the output list)

[] public List<StateOriginModel> GetStateCode_All()
        {
            List<StateOriginModel> results = new List<StateOriginModel>();
                       
            using (var conn = new NpgsqlConnection(pgrstring))
            {
                using (NpgsqlCommand command = new NpgsqlCommand("public.spstateorigincode_getall", conn))
                {
                    conn.Open();
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new NpgsqlParameter("countrycodex", NpgsqlTypes.NpgsqlDbType.Varchar) { Direction = ParameterDirection.Input, Value = LoginDetails.staticcountry.ToUpper() });
                   
                    var reader = command.ExecuteReader();
                    // Bring in Parameters to limit selection to Login.Staticcompany
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            StateOriginModel model = new StateOriginModel();

                            if ((string)reader["StateID"] != null)
                            {
                                model.Id = (int)reader["id"];
                      …
0
Become a CompTIA Certified Healthcare IT Tech
LVL 20
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

This is Windows Forms, C#.

I have a Dataset with 3 datatables.  For datatable ST_MER_POS_Product_Online_List_AA, I want to only keep the rows that have been changed.

1. This is is how I check if the datatable has rows changed:
                  var ttest = IsDataSetChanged(Onlineds); //**** check to see if row is changed
                //var p = Onlineds.ST_MER_POS_Product_Online_List;

               ws.UpdateOnlineProducts_AA(Authorize.MAC_IDs, Onlineds); //call to update 
                this.Onlineds.AcceptChanges();

Open in new window


2. Check to see if row has changed or not
 public bool IsDataSetChanged(DataSet m_DSet)
        {
            if (m_DSet == null)
                return (false);

            foreach (DataTable dt in m_DSet.Tables)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr.RowState != DataRowState.Unchanged)
                        return (true);
                    
                }
            }
            return (false);
        }

Open in new window


3. I  tried dr.Delete(); but I think it deleted all the rows

 public DataSet IsDataSetChangedOnlineProduct(DataSet m_DSet)
        {
            if (m_DSet != null)
            {
                foreach (DataTable dt in m_DSet.Tables)
                {
                    //var p = dt.Rows.Count;

                  //  var p = dt.GetChanges();

                    foreach (DataRow dr in dt.Rows)
                    {
                       if (dr.RowState == DataRowState.Unchanged) 
                       {
                          dr.Delete();

                       }



                    }
                }

                m_DSet.AcceptChanges();

                return m_DSet;
            }


            return m_DSet;
        }

Open in new window


How can I do this?
0
RDLC has issues when running on Internet Explorer 11. How do I identify if a client side computer connected to our website has IE 11. I've read things that say MS tries to hide this by calling it Trident and then vs 11.

Javascript, Jquery, C# all okay for examples
0
I understand that this is not easy to debug and help with but I'm posting some screenshots...hopefully someone can give me an idea where to look and how to do this...

(My first day of working with Crystal Reports and I'm not a CR developer )

1. The report looks like this. You see the tab "Main Report"? I want to add another tab but I don't know how this tab is built. I did a search in the code for "Main Report" and I don't find it. Did a search in stored procs and I don't see "Main Report". Did a search in our Web Services code and I don't see the word "Main Report"
EE-CR.png
2. The report itself looks like this and I see the file

EE-CR-2.png
3. This is the Windows Forms that's the container. Maybe I need to check all the User Controls but still....where is that tab coming from?

EE-CR-3.png
It's ok if no one can help.  I know it's hard to debug it without the code. I can ask my manager if it's ok to give the code and someone here could tell us how this all comes together.
0
Hi, I have an question about what language or technology I can use to do following.
Let say I have an image normally shows as  rectangle with height and width.
I need to transform this image into circle . The same bitmap but not rectangular form but circle form.
Can you suggest what I can use to do this. I program in C#, C++, vb using Visual Studio 2019. If I
need to use another language it is no problem.
0
Working on my first Crystal Report code. It was done by another developer and now I have to make changes to it.

The datasource is a stored proc. I added a new column.

How can I bind the column from the stored proc to the field? The other fields are already there. It's the Phone field I need to add.

EE-CR.png
0
I need to understand how to cast a complex deserialized  Json object to enumerable so that it can be bound to an a gridview

           var enumerable = new[] { GetBuilds().Result};
                       

            GridView1.DataSource = enumerable;
            GridView1.DataBind();

Open in new window




2020-01-13_11-28-21.png


Currently it only results in the top node, i need to get the data in the fields node.

2020-01-13_11-29-37.png
0
I'm planning to get the first letter of  a sentence ignoring propositions like "in , of, etc
For example  The Planning Group of USA. Only what I want to get are  PGU omitting "The" and"of" , or "in" if it shows in C#.
0
How to send String Array ( string [] )in Request Params for REST API in C#?


This does not work.

public string GetLocation(string [] myItems)
{

           //var item = myItems;
            var item = "[\"Alabama\", \"Texas\"]";   //Test    
            var regionCode = "South";


            var url = $"https://MyLocation.com/api/GetLocation?MySearch={ item }&region={ regionCode }";

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.Method = "POST";

            var strResult = string.Empty;

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                strResult = result;
            }

            string myMsgResult = strResult;


}
0
I'm having to support an ancient VB6 application. Currently, I'm writing a COM object class for it. Everything works except for assigning a value to a property. This particular property needs to behave like a VB6 variant data type when used in VB6 code.

I have the simplest little class in C#
    [ComVisible(true)]
    [Guid("1EB35E9B-60EE-4A26-BAEB-6A2D7AC32FF0")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class FooThingy
    {
        private object _value;

        public object Value
        {
            get
            {
                return _value;
            }
            set
            {
                _value = value;
            }
        }

        public FooThingy()
        {

        }
    }

Open in new window

And I call it via the simplest VB6 code. I have added line numbers for easy reference.
Public Sub Main()
    
1    Dim foo As FooThingy
2    Set foo = New FooThingy
3    If (foo.value <> "hello") Then
4        foo.value = "Testing"
5    End If

End Sub

Open in new window

At line 4 it fails with a runtime error 424 "Object required" yet line 3 evaluates with no problem. I know VB6 has this weird distinction between Property Let and Property Set and I'm guessing that is somehow related. What I need to figure out is how do I get my C# class to work with the VB6 code above. Perhaps there's some kind of marshaling declaration that will do the trick? I'm really hoping there's an answer to this because my alternative is to go through this very old VB6 program that was very badly written and find all the places where assignment is being done and replace it with a SetValue() method call which DOES work.
0
Python 3 Fundamentals
LVL 20
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Coding in ASP.NET and C#

Hello Experts,
I am trying to run a Windows Service job only once everyday at a time specified in App.Config file.  How can I use make use of Timer class?  As soon as the job is done, the job will go to sleep mode and again wake up next day.  Is there a simple way?

Here is the requirement.

 1. Process Schedule Task
    Add code to Process the task here
    .
    .

 2. Once the job is executed, reset next run to every 24 hours

Thank you very much in advance!
0
What is the C# code to connect to an Excel file at C:\\Documents\ExcelFile\MarkData.xls? How to read columns and rows and cell addresses of that file? Example also how to delete a row,move data from one row to another row?
1
I have installed the visual studio 2019 community but after some days it showing that my license has expired and I cant use it. Weird because it’s a community edition so shouldn’t it be free? I have done a ton of things – restarted my pc, reinstalled but still the same issue. Can someone guide here…what’s going on?
Thanks
VS-weird-issue.png
0
This question needs a little explanation and background

I have  C# asp.net code that talks to a database and I have javascript on the client end. Javascript makes async calls to the backend c# code via a post and waits for results back. On the client code there is a list of items which get altered based on what the backend page returns.

Currently, when I do any db operation, I then query the db again to get the values of all items on the list and return them back to the client. So any addition, update, deletion...causes me to query the db again and return all items rather than just the one that was altered. This assures that the database and what is on the client list is always the same. But this is inefficient for the db to have that second query.

I'm thinking about simply checking for any errors from the db and then just returning a success or fail and then the javascript can update the list based on values it already had from the submission form.

Is there any way that I could KNOW that the db operation definitely succeeded and there is no chance the db will have different data than the client without having to re-query the db again?
0
I am working on a desktop application using C#, WPF, and .net core 3.1. I was reading on Microsoft's website that DataGrid was being deprecated and should be replaced with DataGridView in .net core 3.1 applications. The issue I am having is that it doesn't seem to actually be supported or at least according to Visual Studio 2019. First, the DataGrid tool still exists in the toolbox while DataGridView does not. In addition, even if I manually type the DataGridView code in VS2019, the code is shown as invalid code. I was looking online and have been having issues finding any info on this so I am guessing I am doing something wrong.

My question is what should I be using, DataGrid of DataGridView? Being it is a new application I would have preferred to use the most up to data version (DataGridView) so my code doesn't break in a year, but if I have to still use DataGrid, I will.
0
Hello Experts,
I am trying to create a Windows Service project, which uploads data from an API.  In one class, I am trying to access an external class name ManageData, with in the same project.  But, getting the below error message.  Please see the attached picture.  Please let me know how to fix it.  Thank you in advance.

Error      CS0246:      The type or namespace name 'ManageData' could not be found (are you missing a using directive or an assembly reference?)

Thank you!
Service.png
0
In C#, what are the differences between using a DataRow, a DataSet or a DataTable? Are these interchangeable? Are there advantages or disadvantages to using one over another? In the scenario I am working with right now I have a dataadapter tied to a command that queries a SQL table. I need to loop through each record and populate an Excel spreadsheet. Right now I have this and it works fine but is there a better, more efficient, way?

MyDataTable dt = new DataTable();                           /* Create the data table to hold the data */
MyDataAdapter = new System.Data.SqlClient.SqlDataAdapter(); /* Create the SQL Data Adapter to contain the returned data */
MyDataAdapter.SelectCommand = MyDataCommand;                /* Assign the SQL data command to the SQL data adapter */
MyDataAdapter.Fill(dt);                                     /* Populate the data table with the results of the query */

foreach (DataRow row in dt.Rows)
{
    Write record to Exel (row["DATA"].ToString())
}

Open in new window

0
Hello,

I'd like to parse part1 and part2 name from my below string structure with Regex.Match.

I don't know it can be appliable but my string is like below;

$J_____dummy_part1_to_part2_sometext

if it's not matching i'd like return string.empty for part1 and part2

Any help would be great!.
Thanks.
0
I have to code a c# solution to convert a txt file to xml using vs 2017.

What is the best way to do this task
0
C++ 11 Fundamentals
LVL 20
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Hi,
I have already done some webform development, however I am thinking of developing a new project and I think it makes no sense to use a technology that I think is becoming obsolete.
As I usually develop in .NET I thought about using Blazor, since I don't have many skills in java framework either.
It makes sense to choose blazor, or it would be better to choose asp.net core controls or another java framework. Will blazor succeed?

best regards
1
Hello Experts
I am trying to download a webpage
and then programmatically clck on any button

AS an example I am using https://www.msn.com/en-us

My visual c# code is as follows

        private void button2_Click_1(object sender, EventArgs e)
        {
            string url = textBox_url.Text;
            WebClient webClient = new WebClient();
            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            webClient.DownloadFileAsync(new Uri(url), @"c:\tmp\aaaaaaa___myfile.txt");
        }

the problem is once I get the source code
I do not get the information of the lower part of the web page.
Like the small squares with additional news not as important as the main body

Why am I not getting the full code of the web page?
Are these js scripts that should be downloaded separately?
REgards,
0
I'm working on a Windows Forms application/desktop written in 2002. Yes, you read that right.... Windows Forms that uses Crystal Reports.

We can't upgrade the code to web at this time. Too many clients on it and the owner doesn't want to invest in a web application.

We want to replace the Crystal Reports section of this application.

These are some of the options we've been talking about:

1. SSRS (a developer here said SSRS is being replaced)
2 . Power BI - how would this work with an old code like the one we have?
3. A developer here said we can write the stored procs and have one of the web developers design and code the pages. Custom web pages that act like reports. Don't think we can do this because clients are not setup for web. They all use our desktop application.

A developer here is pushing for Power BI. I don't know how it would work with Windows Forms/desk top.

Any ideas?
0
For some time now I've been writing C# COM visible DLLs for use in an old VB6 application.

I've recently become aware that my COM visible class isn't browsable in the Object Browser nor does the IDE catch compile-time errors. Here's a sample interface and class:
namespace Sample
{
    [Guid("FDB56085-E1C2-41E3-8B6A-86F734B9338B")]
    public interface ITest
    {
        #region Methods

        void Foo();
        void Bar();

        #endregion
    }
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("6717C7FC-9E3F-47A1-955C-09734F96B18F")]
    public class Test: ITest
    {
        #region Public Methods

        public void Foo()
        {

        }

        public void Bar()
        {

        }

        #endregion
    }
}

Open in new window

All this compiles fine and any code I insert into Foo() or Bar() will execute without a problem. However, I can also do this in VB6:
    Dim tAs Sample.Test
    t.Foo
    t.Bar
    t.CompileError

Open in new window

and the compiler doesn't complain at all. At runtime the last line does generate an error indicating that the method is not implemented but nothing at compile time. Also, the entire class is not browsable in the Object Browser. I can live with the 2nd part but I'm hoping there's a way to force the compiler to catch such errors during compilation. Any suggestions?
0
Hello Experts,
I have a Console App, which imports some data thru an API call.  In this all the methods are defined inside the Main().  I am trying to define some methods such as xxxSearch and XxxxDetail, return type List, outside of the Main() method.  When I do that, I am getting the Error: CS0120 An object reference is required for the non-static field, method, or property 'XxxxImport.XxxxSearch(DateTime, DateTime)'.

The reason I need to do this, because I need to convert this to a Windows Service Program comfortably.

Please let me know how to define them outside of Main() method and call them,

Thank you very much in advance.

Below is the Skeleton of the Code
----------------------------------------------------

public static void Main(string[] args)
{
    DataSet ds = new DataSet();

    var fromDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(-1);
    var toDate = DateTime.Parse(fromDate.ToString("yyyy-MM-dd")).AddDays(0);

    MainHub(fromDate, fromDate);

    Environment.Exit(0);


    void MainHub(DateTime FromDate, DateTime ToDate)
    {
      var xxxFound = xxxSearch(FromDate, ToDate);

      if (xxxFound != null)
      {
          InsertxxxRaw(xxxFound, FromDate);
      }

      foreach (var xxx in xxxFound)
      {
          var list = new List<string>();
          list.Add(xxx.xxxNumber);

          var details = xxxDetail(xxx.validatingxxxDesignator, list);

          if (details != null)
          {
            …
0
Hi
I'm trying to use HtmlAgilityPack to Travers some  HTML Test.html

Under each b-post will be a single picture, a group of pictures in a slide show or a video I'm struggling to extract the elements like Title for  each post &  img src

  class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            string Root = @"H:\TopTotty\CarrieLaChance\onlyfans\Vids\";
            string CarrieOF = Root + "Test.html"; // "CarrieOF.html";
            var htmlDoc = new HtmlDocument();
            htmlDoc.Load(CarrieOF);


                var bPostNodes = htmlDoc.DocumentNode.SelectNodes(".//div[contains(@class,'b-post')]");

            string Title = "";
            string VidSrc = "";
            string Poster = "";
            foreach (var divNodes in bPostNodes)
                {
                ///html/body/div/main/div/div/div[2]/div/div[2]/div[2]/div[1]/div[1]/div/a/span
                //Title = divNodes.SelectSingleNode(".//span").Attributes["title"].Value;
                try
                {
                    ///html/body/div/main/div/div/div[2]/div/div[2]/div[5]/div[1]/div[1]/div/a/span
                    if (divNodes.SelectSingleNode(".//span").Attributes["title"] != null)
                    {
                        Title = divNodes.SelectSingleNode(".//span").Attributes["title"].Value;
                    }

                    // 

Open in new window

0

C#

94K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).