|
You connect to a sql db using a connection string. Somewhere in your code or web.config or app.config (depending on what type of project you have) is a connection string which tells the code how to connect to the sql database.
You can either put the database somewhere everyone has access to and update your connection string to point to it or you can expose your database on the network, which it might already be.
|
|
|
|
|
Google "sql server allow remote connections"
|
|
|
|
|
I' ve a ComboBox with Three Items in main Form and a button make another form.show so in the second form i am asking about the selected item in the combox and switch it in 3 cases but i ve an error said nullReference the item is null even i select one item from the Combox ( "Tete", "Doublette", "Triplette")
Thank you for Your Help
|
|
|
|
|
Without seeing the relevant code, it's impossible to tell you anything useful beyond something is null and you're trying to use a property or call a method on it.
|
|
|
|
|
|
A "selected item" is not "valid" unless the .SelectedIndex is > -1 (i.e. >= 0);
A "list control" can have items, but the SelectedIndex says whether or not it is actually "pointing" at something.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
The Form is a container for controls, so you cannot access it directly from another form/class especially when controls have private modifiers. Using access modifiers may still cause some issues. Its better to access the control using Controls class.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnStart_Click(object sender, EventArgs e)
{
comboBox1.Items.Add("Combo Item");
}
}
public class GetComboItem
{
public GetComboItem()
{
ComboBox cmbItm = Application.OpenForms["Form1"].Controls.Find("comboBox1", true)[0] as ComboBox;
MessageBox.Show(cmbItm.Text);
}
}
|
|
|
|
|
Eventually I decided to start with the functional concept and installed the LanguageExt library (see GitHub - louthy/language-ext: C# functional language extensions - a base class library for functional programming[^] ). In our code base, there is a class which is full of bool TryGet(some parameters, out T result) functions - I want to change them to Option<T> TryGet(some parameters) .
But then, things start to look ugly at a different level. E.g.
List<PointF> result = new List<PointF>();
...
foreach (IIntersectionInfo intersection in intersections)
{
Option<PointF> angle = m_Geometry.TryGetAnglesForPosition(intersectionPoint, _name);
if (angle.IsNone)
{
Logger.LogWarning(Name, $"Cannot determine angle for position '{intersectionPoint}' corresponding to pixel '{pixel}'.");
}
else
{
result.Add(angle.IfNone(PointF.Empty));
}
} There are two kinds of ugliness:
- I have to use the IfNone(PointF.Empty) clause even when angle is guaranteed to be Some there.
- I do not know how to get rid of the foreach in this situation.
How can the code become clean?
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
If you didn't want to log the failures, it could be as simple as:
m_Geometry.TryGetAnglesForPosition(intersectionPoint, _name).IfSome(result.Add); Otherwise, something like this should work:
m_Geometry.TryGetAnglesForPosition(intersectionPoint, _name).Match(
point => result.Add(point),
() => Logger.LogWarning(Name, $"Cannot determine angle for position '{intersectionPoint}' corresponding to pixel '{pixel}'.")); There's also the C# 8 property patterns:
if (m_Geometry.TryGetAnglesForPosition(intersectionPoint, _name) is { IsSome: true } angle)
{
angle.IfSome(result.Add);
}
else
{
Logger.LogWarning(Name, $"Cannot determine angle for position '{intersectionPoint}' corresponding to pixel '{pixel}'.");
} Or you could define a deconstructor as an extension method:
public static class OptionTExtensions
{
public static void Deconstruct<T>(this Option<T> option, bool isSome, T value)
{
isSome = option.IsSome;
value = isSome ? (T)option : default;
}
}
...
var (isSome, point) = m_Geometry.TryGetAnglesForPosition(intersectionPoint, _name);
if (isSome)
{
result.Add(point);
}
else
{
Logger.LogWarning(Name, $"Cannot determine angle for position '{intersectionPoint}' corresponding to pixel '{pixel}'.");
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, that was the major step for this issue.
Afterwards, I could figure out the
var tmp = intersections.Map(_intersection => m_Geometry.TryGet...ToList() monstrosity abolishing the foreach(... intersections) .
Functional programming feels odd when trying it for the first time.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Develop a Window Form Application in C# to fulfill the functionality of given below form. Functionality of each button is explained below.
i) Add Employee button will add new employee in DB with unique ID.
ii) Delete and Update Employee will be on the basis of employee ID.
iii) Retrieve All Employee button will retrieve all employees from DB table and populate into grid view control.
iv) Update Employee will update the existing employee; it Search employee on the basis of its ID.
Apply Exception handling in the code and Before the Employee Record is Saved to Database, apply the following Data Validation Checks
1. ID should be distinct and it should not be duplicated in the Table
2. ID, Name, Designation and Salary should not be null
3. ID and Salary should be non-negative, greater than Zero and Positive Values
4. Name and Designation Length should be greater than 6 Characters and Name should not contain any Digit (0-9)
5. Before any DML Statement is executed (Insert Into, Update or Delete), Ask User using MessageBox whether He/She really want to Add / Update / Delete the Record. When user press the OK button on the MessageBox then Record DML statement should be executed.
|
|
|
|
|
No.
Nobody here is going to do your homework for you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Okay. I've done that. What now?
|
|
|
|
|
Email it to his teacher to save him the effort?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Sort of like poking a stick into a hole and seeing if something will grab onto it. I like picturing grizzly bears.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
As others have pointed out, no one here is going to write your program for you. Let's step back from that statement for a second and consider why we won't do that.
The first point is that, for the most part, we are all professional programmers on this site and what you are asking is for someone to build something for you, for nothing. Imagine going onto a site for construction workers and posting a blueprint of the house you want building. How many responses do you think you would get saying they would build it for you?
Next, you have to remember that we know what you're asking for here. You're asking for us to write your homework for you and that's asking for us to help you to cheat. You might not see that as a big thing but we do. If you don't understand how to do this task and someone helps you cheat then you haven't learned how to do this task. At some point in the future, you may end up working alongside one of us and we could have to make up for the fact that you have come into the profession not knowing how to do a simple task like this. You already have all of the requirements here so it should be a simple enough task for you to work out how to do this.
If the reason you want to cheat is because you don't know how to do this task then that's probably down to one of these three reasons.- You haven't been taught how to accomplish the parts of this task. If that's the case, you need to talk to the person who set out the task to get guidance
- You have been taught it, you just weren't paying attention. Well, that's on you. Don't expect us to dig you out of that hole
- You have been taught how to do this, but you don't have the aptitude to be a developer. There's no shame in this, there are always things we aren't capable of doing. I'm not capable of flying a fighter jet at Mach 2, I'm not going to feel ashamed over that. If you aren't meant to be a developer, find something else you can do. Don't continue struggling over things that you aren't meant to be.
|
|
|
|
|
Can someone show me how to send GMmail using C#???
I just spent an hour Googling and the closest thing that I found was this page which only lists the folders in my gmail account. This seems like it's WAYYYY over conmplicated.
I tried this based on some snipptes I got off Google, but I get auth errors
class Program
{
static void Main(string[] args)
{
var client = new SmtpClient("smtp.gmail.com", 465)
{
UseDefaultCredentials = false,
Credentials = new NetworkCredential("me@gmail.com", "mypass"),
EnableSsl = true,
};
client.Send("me@gmail.com", "me@gmail.com", "Test", "This is a test");
Console.WriteLine("Sent");
Console.ReadLine();
}
}
I get either "Failure sending email" with port 465, or "'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required" usig port 587.
I thought it would be as simple as this, bu there doesn't seem to be a clear example that works.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Depending on your account settings, you may need to create an app password to allow your application to bypass 2SV:
Sign in with App Passwords - Google Account Help[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
okay, we know that's not possible via the usual save/restore techniques for damn good reasons:
1) Func and Action (delegates) can have references to external objects/states the compiler can't resolve.
2) if that could be done, it would be an ideal way to insert/execute malicious code.
as i see it, now, that leaves two alternatives:
1) have some kind of plug-in architecture that exposes pre-defined delegates. but, that could also be vulnerable to security threats. more critical would be the delegates defined in the plug-in need for access/reference to the definitions/references of internal objects in the app it would manipulate.
2) a DSL/script-language that could be saved/restored as text, and then compiled via Roslyn reflection/emit, etc.
a concrete example of the type of Func i'd iike to save:
private static readonly Random rand = new Random();
private double IntensityFunc(Edge edge)
{
var hour = DateTime.Now.Hour;
if (hour > 3 && hour < 12) return edge.IntensityMin;
if (hour > 22) return edge.IntensityMax;
return rand.NextDouble() * (edge.IntensityMax - edge.IntensityMin) + edge.IntensityMin;
} mini-example showing Node and Edge definitions, and Func usage:
public class Node: INode
{
public Node(string name, int id)
{
Name = name;
Id = id;
}
public string Name { set; get; }
public string Id { set; get; }
}
public class Edge: IEdge
{
public Edge(Node node1, Node node2, double intensity, double intensityMin = 0.0, double intensityMax = 0.0,
Func<Edge, double> intensityFunc = null)
{
Node1 = node1;
Node2 = node2;
Intensity = intensity;
IntensityMin = intensityMin;
IntensityMax = intensityMax;
IntensityFunc = intensityFunc;
}
public Node Node1 { set; get; }
public Node Node2 { set; get; }
public double Intensity { set; get; }
public double IntensityMin { set; get; }
public double IntensityMax { set; get; }
public Func<Edge, double> IntensityFunc { set; get; }
public double GetIntensity()
{
return IntensityFunc?.Invoke(this) ?? Intensity;
}
}
private void Form1_Load(object sender, EventArgs e)
{
var Jack = new Node("Jack", 1);
var Jill = new Node("Jill", 2);
var JackToJill = new Edge(Jack, Jill, 50.0, 20.0, 80.0);
var jintensity = JackToJill.Intensity;
JackToJill.IntensityFunc = IntensityFunc;
for (var i = 0; i < 20; i++)
{
var jintensity2 = JackToJill.GetIntensity();
Console.WriteLine(jintensity2);
}
}
private double IntensityFunc(Edge edge)
{
var hour = DateTime.Now.Hour;
if (hour > 3 && hour < 12) return edge.IntensityMin;
if (hour > 22) return edge.IntensityMax;
return rand.NextDouble() * (edge.IntensityMax - edge.IntensityMin) + edge.IntensityMin;
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 7-Dec-20 18:15pm.
|
|
|
|
|
A Thread.Sleep(n) will pause the current thread for at least n milliseconds. But there are some caveats: Thread.Sleep(1) takes at least some 15 ms on "common" Windows 7/8/10 due to the "time slice" management of threads. In contrast, running the same code with mono on Linux, the sleep time may get close to 1 ms. I haven't found any information on Windows 10 IoT for that feature.
Already this simple example shows that Threads are dealt with differently depending on the underlying platform.
Where can I find more information on that feature?
The main interest is differences between Windows 10 Pro and Windows 10 IoT, but also information beyond that is appreciated.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Worse yet, Thread.Sleep doesn't even guarantee that the thread will actually give up its time slice. If there are no other threads ready to run at the same priority, your Thread is not suspended.
T minimum time a Thread can "sleep" is dependent on the system timer and its resolution. The timer is dependent on hardware and O/S implementation. From the Sleep function[^] in the Win32 documentation:
Quote: The system clock "ticks" at a constant rate. If dwMilliseconds is less than the resolution of the system clock, the thread may sleep for less than the specified length of time. If dwMilliseconds is greater than one tick but less than two, the wait can be anywhere between one and two ticks, and so on. To increase the accuracy of the sleep interval, call the timeGetDevCaps function to determine the supported minimum timer resolution and the timeBeginPeriod function to set the timer resolution to its minimum. Use caution when calling timeBeginPeriod, as frequent calls can significantly affect the system clock, system power usage, and the scheduler. If you call timeBeginPeriod, call it one time early in the application and be sure to call the timeEndPeriod function at the very end of the application.
|
|
|
|
|
I created a program
class Program
{
static void Main(string[] args)
{
double b;
double h;
Console.WriteLine("Basis: ");
b= Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Height: ");
h= Convert.ToDouble(Console.ReadLine());
double area1 = Program.calcArea(b, h);
Console.WriteLine("The area of triangle 1 is: ");
Console.WriteLine(area1);
Console.ReadLine();
}
public static double calcArea(double b, double h)
{
return b * h / 2;
}
}
}
It works, but I have to do it twice, what's the solution?
|
|
|
|
|