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 wonder, given some program source code, and applying small incremental refactorings, is it always possible to get from any starting code to any other code configuration where the code still retains all the functionality of the original code, or are there valid code configurations which cannot be achieved through refactoring?

For example, starting with code which sorts using Bubble Sort, is it possible to refactor that using small incremental refactorings and end up with a much better sorting algorithm, such as Heapsort or Quicksort?

(I suspect not. I suspect the only way to go from Bubble Sort to Heapsort would be to first analyze the Buble sort code and realize on a higher level what the code is achieving, namely that this bit of code is a "Sorting Algorithm", and then one can replace that sorting algorithm with any other sorting algorithm, but the swap I'm guessing consists of fully replacing the algorithm with a different algorithm which accomplishes the same thing; I'm guessing there are no smaller incremental refactoring steps that could be made without understanding the higher concept of what the code is trying to achieve.)

Is my hunch correct? Has any mathematician examined this to prove what better code configurations are reachable and which ones are not, by using only standard refactoring techniques, without understanding the "goal" of the code?

(I'm kind of fudging because I'm sure someone will say "replace one algorithm with a better one" is a …
0
Rowby Goren Makes an Impact on Screen and Online
LVL 13
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Hi
I'm attempting to update my local movie database from information from the movie database API (TMDB API)
This picture shows my Entity Framework diagram
MovieModel3.JPGthere are several issues I need to address

People with no tmdb_id or profile path ( Every person on TMDB should have an id but not all have a picture)

movielinkperson.job as few entries, for cast this is the  cast.Character and for crew it's job eg Director

Wrong person linked to a movie

TMDB Person in the database but not linked to a movie or not in the database

Searching TMDB by persons name is ambiguous for instance search for "John Wayne" returns 13 people  

I there for need to search for people linked to movies in the database and update accordingly

In the code below I'm struggling with the logic and with this line

// this is supposed to create a movielinkpersons object but isn't happy with code after &&
  var MLP = context.movielinkpersons.Where(m => m.movieId = Movie.id && x => x.personId == PersonExists.id);

        private void UpdateBtn_Click(object sender, EventArgs e)
        {
            TMDbClient client = new TMDbClient("2c8a02fa36fb5299dcd97bbc84609899");
            using (var context = new MoviesEntities())
            {
                var allMovies = context.movies.OrderBy(m => m.title).ToArray();
                // make a list so not processing a person twice
                

Open in new window

0
Hi,

I am trying to create a CLR function to allow users to grab data from a table that changes names each month (name changes are outside my control).

I have everything compiling and running without any errors but I never get any rows back.

I have simplified things as much as possible to try to find the problem and am inserting a DataRow into the DataTable I want to return to rule out problems with the select but still don't get any rows.

C# code
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.IO;
using Microsoft.SqlServer.Server;


public class TableFunctions
{

    [SqlFunction(FillRowMethodName = "FillCLRTest")]
    public static IEnumerable CLRTest()
    {
        string query = "SELECT [id]" +
                "FROM table";

        DataTable results = new DataTable();

        try
        {
            using (SqlConnection conn = new System.Data.SqlClient.SqlConnection("context connection = true"))
            using (SqlCommand command = new SqlCommand(query, conn))
            using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
                dataAdapter.Fill(results);

            DataRow dummyRow = results.NewRow();

            dummyRow[0] = "1234";
            results.Rows.Add(dummyRow);

            return results.Rows;

        }
        catch (Exception e)
        {

        }

        return null;


    }

    public static void FillCLRTest(Object 

Open in new window

0
I have a feeling I might be going about this the wrong way. I'm hoping there's a solution to what I want to accomplish.

I have the following colors defined in a resource dictionary
    <SolidColorBrush x:Key="Add.Border" Color="#FF4BAE53"/>
    <SolidColorBrush x:Key="Add.Background" Color="#FF5BB862"/>
    <SolidColorBrush x:Key="Add.Hover" Color="#FF439D4B"/>
    <SolidColorBrush x:Key="Add.Pressed" Color="#FF38843E"/>
    <SolidColorBrush x:Key="Add.Disabled" Color="#A55BB862"/>
    <SolidColorBrush x:Key="Add.Foreground" Color="White"/>

    <SolidColorBrush x:Key="Edit.Border" Color="#FFECA040"/>
    <SolidColorBrush x:Key="Edit.Background" Color="#FFEEAC55"/>
    <SolidColorBrush x:Key="Edit.Hover" Color="#FFEA952E"/>
    <SolidColorBrush x:Key="Edit.Pressed" Color="#FFD38323"/>
    <SolidColorBrush x:Key="Edit.Disabled" Color="#A5EEAC55"/>
    <SolidColorBrush x:Key="Edit.Foreground" Color="White"/>

    <SolidColorBrush x:Key="Delete.Border" Color="#FFD33B3B"/>
    <SolidColorBrush x:Key="Delete.Background" Color="#FFD85050"/>
    <SolidColorBrush x:Key="Delete.Hover" Color="#FFC82B2D"/>
    <SolidColorBrush x:Key="Delete.Pressed" Color="#FFAA2526"/>
    <SolidColorBrush x:Key="Delete.Disabled" Color="#A5D85050"/>
    <SolidColorBrush x:Key="Delete.Foreground" Color="White"/>

Open in new window

I'm creating a custom control that will use these colors as a palette. The actual colors it will use will be determined by a property I'm calling "Purpose". That purpose will be Add, Edit, or Delete. I already have that property working. What I don't have working is being able to select the Delete.Background color if the value of "Purpose" is Delete vs. the Add.Background color if the value is Add. Is this even possible? Is there perhaps another way I should be defining my colors in the resource dictionary to make this work properly?
0
I'm still learning the mechanics of this whole WPF thing. I'm creating a user control. One of the things I want my control to be able to do is respond to click events of a control on the parent window. To do this, I have created a property called "Activator" like this:
		public DependencyObject Activator { get; set; }
		public static readonly DependencyProperty ActivatorProperty = DependencyProperty.Register("Activator", typeof(DependencyObject), typeof(NavView));

Open in new window

I then markup my Xaml like this:
                <Button Name="buttonShowHideMyControl" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Style="{DynamicResource HeaderButton}" Grid.ColumnSpan="2" Margin="0,4,9,0">
                    <fa:FontAwesome Grid.Column="2" Icon="Bars" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="White" FontSize="24" Margin="10,4,0,4"/>
                </Button>
            <local:TestUserControl x:Name="testUC" Grid.Column="1" HorizontalAlignment="Right" Visibility="Hidden" Opacity="0" Activator="{Binding Property, ElementName=buttonShowHideMyControl}">
                
            </local:TestUserControl>

Open in new window

0
Can you please tell me why this routine is not showing values in the text box when i click in the text area?
screenshot.JPG
      private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox i = sender as ListBox;
            if (i.SelectedIndex != -1)
            {
                listBox1.SelectedIndex = i.SelectedIndex;
                listBox2.SelectedIndex = i.SelectedIndex;
                txtID.Text = listBox1.SelectedItem.ToString();
                txtName.Text = listBox2.SelectedItem.ToString();               
            }
        
        }

Open in new window

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, 

Open in new window

0
Can you please help me in that error?
screenshot.JPG
namespace InsertUpdateDel
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.txtID = new System.Windows.Forms.TextBox();
            this.txtName = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.listBox2 = new System.Windows.Forms.ListBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            

Open in new window

0
Hi,

How can I use LINQ to remove entries from one list of items matching values from another list.

Please the code below for more details.

Thanks,

Ward

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml.Serialization;
// using ClosedXML.Excel;

using ClosedXML.Excel;
using DocumentFormat.OpenXml;
using ExcelHelper;

namespace Linq_Test_1
{

    public class Person
    {
        public int Index { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }

}
    class Program
    {
        static void Main(string[] args)
        {
            var rand = new Random();
            var people = Enumerable.Range(0, 100).Select((x, i) => new Person { Age = rand.Next(1, 101), Name = $"Name{x}", Index = i }).ToList();
            var results = people.OrderByDescending(x => x.Age).ToList();

            List<int> remove_list = new List<int>();

            for (int i=1;i<=20;i++)
            {
                int random_key = rand.Next(1, 101);
                remove_list.Add(random_key);
            }

            // <-- How to do the code below via Linq -- RemoveAll?

            List<Person> new_list = new List<Person>();

            foreach (Person p in people)
            {
                bool matched_flag = false;

                foreach (int key in remove_list)
                {
                    if 

Open in new window

0
Can you please help me in that error?
Error in List Box[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtID.Text != "" & txtName.Text != "")
            {
                cn.Open();
                cmd.CommandText = "Insert into info(id, name) values ('" +txtID.Text+"', '" +txtName.Text+"')";
                cmd.ExecuteNonQuery();
                cmd.Clone();
                MessageBox.Show("Record Inserted", "Programming");
                cn.Close();
                txtID.Text="";
                txtName.Text="";
                loadlist();
            }
        }
        …
0
Can you please tell me what this error means?

Error statement: sd = cmd.ExecuteReader();

screenshot.JPG
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtID.Text != "" & txtName.Text != "")
            {
                cn.Open();
                cmd.CommandText = "Insert into info(id, name) values ('" +txtID.Text+"', '" +txtName.Text+"')";
                cmd.ExecuteNonQuery();
                cmd.Clone();
                MessageBox.Show("Record Inserted", "Programming");
                cn.Close();
                txtID.Text="";
                txtName.Text="";
                loadlist();
            }
        }

Open in new window

0
PMI ACP® Project Management
LVL 13
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

I have a List<A> listA a list of objects of type A. I want to make a new list. Is there any difference between the following:
given: List<A> listA
var List<A> newListA = new List<A>(listA);
var List<A> newListA = new List<A>(listA.ConvertAll((x) => (A)x));

Open in new window

I'm trying to figure out why some old code has this .ConvertAll in it and if it's necessary.
0
I have a C# WCF application that I've been working on. It contains 2 sites, an external one and an internal one.

Previously they have both worked perfectly. I have local urls for each app defined in IIS pointing to 2 different AppPools. I am using a defined user and have given this user Full Control for the entire directory structure of the app's code as well as Permissions on each of the apps and set the identity for each AppPool. When I click on the Test Settings button, they both show green checks next to the Authentication and Authorization.

I recently had to delete my local repo and Clone the one from our TFS server. The external one no longer runs saying that Access is Denied. The internal app works perfectly.

Any ideas on what I can check to help figure out why this is happening?
0
Hi,

How can I take the results of a Linq Query and convert to XML and save to file.

I have provided some same code below.

Thanks,
Ward

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Linq_Test_1
{

    class Person
    {
        public string Name;
        public int Age;
    }
    class Program
    {
        static void Main(string[] args)
        {
            List<Person> People = new List<Person>();

            Random rnd = new Random();

            for (int i=1;i<=100;i++)
            {
                Person person = new Person();

                person.Name = "Name" + i.ToString();                
                person.Age = rnd.Next(1, 101);
                People.Add(person);
            }

            int counter = 1;
            var results = from Person in People orderby Person.Age descending
                         select new
                         {
                             Name = Person.Name,
                             Age = Person.Age,
                             Index = counter++ 
                         };


        }
    }
}

Open in new window

0
I have a question regarding SQL permissions. I have a C# application that calls stored procedures. This application is wrapped around an ERP solution. This solution grants rights through a group. My stored procedures run fine on all the database that are part of the ERP solution. There is one stored procedure that runs against a database that is outside of the ERP solution. I have given user db_reader, db_writer and db_owner roles on the external database. These users are getting permission denied on this external database. What other role(s) must I give them? Is there something I need to grant on a table level?
0
I have a checkbox panel and I am adding the text for check box like this

chkPanel.Controls.Add(new CheckBox { Text = "Savings" + "This text needs to be red and bold", Checked = true, Enabled = false });
chkPanel.Controls.Add(new LiteralControl("<br />"));
chkPanel.Controls.Add(new CheckBox { Text = "Checking" , Checked = false, Enabled = false });


where you see "This text needs to be red and bold"  i actually want that text to be red and bold.  is it possible. if yes how?
0
I have two lists:
List<A> listA of objects A
List<B> listB of objects B

I also have a method which can take any pair of A and B and return a Boolean True or False:
bool TestAB(A a, B b)

Open in new window


Now I want to process all possible combinations of elements from listA and ListB,
for each pair {a, b} if TestAB(a, b) returns True then add element a to List<A> listApass, and add element b to List<B> listBpass. No duplicates in listApass or listBpass.


The other variation on this idea is if I have one listA of A elements and I want to process all possible pairs of elements from the same list (n things taken 2 at a time). This time I have a method TestAA(A a1, A a2) which returns a Boolean true or false, and I want to make a list of all pairs of elements for which the test is true (so I'd need a class which holds a pair of AA, we'll just call that class AA, it holds a pair of {a1, a2}, and we'll have a List<AA> listAA which is a list of all the pairs.)


(If that doesn't make enough sense, then here's how it would be done in CE# without Linq:
List<A> listA = new List<A>{ a1, a2, a3 }
List<B> listB = new List<B>{ b1, b2, b3 }

List<A> listApass = new List<A>();
List<B> listBpass = new List<B>();

foreach(A a in listA)
{
    foreach(B b in listB)
    {
        if (TestAB(a, b))
        {
            listApass.Add(a);  // but only if listApass does not already contain a
            listBpass.Add(b);  // but only if listBpass does not already contain b
        }
    }
}

Open in new window


I suspect there's a nice Linq way of doing this.

And for the second related question, the old C# code would be something like:
var listA = new List<A>{ a1, a2, a3 }
var listAA = new List<AA>();

for (int i=0; i < listA.Count; ++i)
{
    for (int j = i+1; j < listA.count; ++j)
    {
        if (TestAA(listA[i], listA[j]))
        {
            listAA.Add( new AA(listA[i], listA[j]) );
        }
    }
}

Open in new window

Again I assume this is something Linq would be well suited for. (I'm just not familiar with Linq yet.)
Thank you!
0
I have a C# ASP.NET Webform which fails on a Response.Redirect.  When I look at the resolved Url in variable myUrl it is "/WebForm1.aspx" whereas I would have expected that it would contain "C:/Users/PatClarke/source/repos/TiosClient/TiosClient". I am running this locally in debug mode. Why would ResolveUrl return Blank for the path ?


                try
                {
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    string myUrl = ResolveUrl("~/WebForm1.aspx");
                    Response.Redirect(ResolveUrl("~/WebForm1.aspx"));
                }
                catch (Exception ex)
                {
                    MyGlobals.logger2.Information("Error encountered: {error} ", ex);

                }

Open in new window


The exception ex contains "ExceptionState = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."

What am I doing wrong ? I have granted everyone permission to the directories in question.
0
Forgive my ignorance. I'm still learning xaml.

I have this button:
                <Button Name="CloseButton" DockPanel.Dock="Top" HorizontalAlignment="Right" Style="{StaticResource TitleBarButton}" Click="CloseButton_Click" Tag="Images/Window/close.png">
                </Button>

Open in new window

This is the style definition I have so far:
    <Style x:Key="TitleBarButton" TargetType="Button">
        <Setter Property="Width" Value="34"/>
        <Setter Property="Height" Value="26"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="1,0,1,1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border x:Name="border" Background="Transparent" BorderBrush="Transparent" BorderThickness="1,0,1,1" >
                        <Image Source="{Binding Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" Stretch="None"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Background.Color" To="#FFFFFCF4" Duration="0:0:0.2"/>
                          

Open in new window

1
Very complicated program here with Visual Studio 2017 in C#.

When I created the solution a default form came up.

I added a button.

What code, if any, would I add to the button click event to close the form?
0
OWASP: Forgery and Phishing
LVL 13
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Hi
In the code bellow I'm getting null because the profile path in the database can be  null

How do I test for this so it dosn't throw a  NullReferenceException

as can be seen in the picture person isn't null person.JPG

        public ActorBox(person person)
        {
            InitializeComponent();
            this.person = person;
            if( (person.profile_path.EndsWith( "JohnWayneBig.png")) || ( person.profile_path is null) )
            {
                ThumbPhotoPath = ImgPath + "JohnWayneSml.png";
                FullPhotoPath = ImgPath + "JohnWayneBig.png";

            }
            else
            {
                ThumbPhotoPath = ImgURL + "w45" + person.profile_path;
                FullPhotoPath = ImgURL + "original" + person.profile_path;
            }
            

            ThumbPictureBox.LoadAsync(ThumbPhotoPath);
            ActorNameLbl.Text = person.name;
        }

Open in new window



System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=FilmsDB
  StackTrace:
   at FilmsDB.ActorBox..ctor(person person) in D:\Vb\MovieDB\FilmsDB\ActorBox.cs:line 34

Open in new window

0
I'm refactoring some legacy code.

The code has a class A, and a List<A> list of these items.

Elsewhere there is stored a List<int> list of integers. The integers are used to access elements from the List<A> list. Each integer is an index into the List<A>. So the integers act as pointers to elements of type A in List<A>.

I'm thinking there's got to be a better way, a more modern OOP way I can refactor this.

Given integer i from List<int>, it's not explicit that this is a pointer into List<A>. That's "god" knowledge that only the programmer knows.

I thought how about convert the List<int> into another List<A>, however I don't want to have 2 copies of the elements. (I already have that problem implicitly, as if List<A> changes, that could invalidate the contents of List<int>. List<A> needs to be one which can only grow, and never have elements removed.)

What would be a more OOP oriented design for this situation of wanting a subgroup of a List?

(Maybe it's OK to have two copies of the elements? One in the original List<A>, and the other in the sublist? It's not clear yet if the contents of A are invarient or might change.)
0
Hi!

After two hours in a support call, I could not figure out how to do something that every tech support article in cyberspace outlines to do in Crystal Reports, when you have to summarize a formula.  (Crystal won't let you do so, conventionally.)

I tried the variables where you conduct "x:= while printing records" but to no avail.

If anyone out there has had a challenge with this, please tell me what you did to overcome it.

As best as I can tell you and as best as I can remember from the support call, there is a formula in Group Footer #1 - not in Details - and I need to have a subtotal for this appear in Group Footer #2.

I created several "variable" formulas, I put them in this header, that header, this footer, that footer, the Report Footer, the Report Header, etc.

I did everything to the letter, but I still could not get a simple subtotal to appear.

Please help.

Thanks!

John
0
I have a high throughput c# console app which is saving around 250-350 records a sec to a log table (sql server 2017 enterprise)

We are looking at ways to increase performance and sometimes a report is run on the table and things grind to a halt
We are also struggling to keep up at busy times

We currently do not use partitions, and are investigating this
We also insert one record at a time, and attach the insertedID to the c# object of log data for further operations

I'm considering partitions, however i'm not sure what to partition on hour, day, week month
We generally store 6 months of historical data (could also be 1 month or 24 months for smaller number of IOT devices.)
data is usually queried by day, last 7 days, week, month, and sometimes custom date ranges.
I would welcome ideas and comments about what is the best option here, we write more than we query, but queries will span multiple days/weeks

I'm also considering a different approach on inserting, instead of one at a time, do a batch insert.
However i'm unsure how I can then associate the database insertedID with C# object.
Currently its one at a time, so i just add the insertedID to the object, and send that off to messages queues for further processing,

I was looking at the SQL OUTPUT and inserted.ID but not sure when batching 500 records how to marry the inserted ID with the c# object

So in summary I would welcome ideas on
1) partition setup
2) batching inserts and marrying the …
0
I am a C# newby with a recently upgraded Epicor software and need some help.

I need some code to put in a query and have no clue how to write it.  In the ABL language I was used to it would be something like this

If IsNull(LaborHed.PayrollDate) then Today
else LaborHed.PayrollDate

In my own words I want to check if a date field is blank or null.  If it is blank or null then put in today's date otherwise use the date in the field.
0
Hi. I read data from GPS using Serial port in C#. It is working ok.
 if I disconnected  GPS then gps information cannot be showed to user but something like "No data" have to be showing . Unfortunate I cannot find how to do that.
Nothing can be done here:
  public void SerialPort_DataReceivedAsync(object sender, SerialDataReceivedEventArgs e) // data received event from COM port
        {
   
            SerialPort port = (SerialPort)sender;
            _buffer = new byte[port.BytesToRead]; // byte count readable from COM port
            port.Read(_buffer, 0, _buffer.Length); // read data from COM port and fill out it into buffer
'''''''''''''''''''''''''''''''
}
or here
  public event DataArrivedHandler DataArrived // manager to add or remove event
        {


            add { lock (this) { _dataArrived += value; } }

            remove { lock (this) { _dataArrived -= value; } }
        }
How can I inform user that there is no GPS connection , not only when user connect to GPS but also when it is already connected?
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).