|
you're welcome.
|
|
|
|
|
I have a asp form what I want if the form validation is true then the page should be refresh and all the fields should be clear and if the validation is not true the page should not be refresh and the form data should not be cleared.
|
|
|
|
|
You still "refresh" on error; except, you "return" all the data, with appropriate "error info", so the user can correct.
A favorite seems to be to say there are errors and to return an empty screen so you can start over (sloppy banks and insurance companies). Oh, and don't forget to timeout in a ridiculous short amount of time; like, too short, to check some papers (the first time).
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
If I make a new project in Visual Studio and give it the name Welcome Program, then I see this in the code window:
namespace Welcome Program
Okay I am aware that a namespace helps organize things better and helps keep things separate, but this is not needed in a console program. But if I delete this line in a GUI program the program will not build. Is this just simply something Microsoft decided to build into their language? It has to be there when making a GUI?
And my second question is about this line:
Public Partial Class MainWindow:Window
All I know about this is that a partial class allows you to split the class definition among more than one file. This line also has to be there. What does MainWindow:Window mean? What is the purpose of the colon?
|
|
|
|
|
All of your code goes into classes. Classes ALWAYS go into a namespace. You cannot have a class without it being in a namespace, even in a console app.
MainWindow is the name of your class. The ": Window" part means the class inherits from a class called "Window".
|
|
|
|
|
'NameSpaces [^] control semantic scope: the context in which specific names (Classes, Methods, Fields, Properties, etc.) have meaning. They are a tool you can use to organize your code, and, when using different libraries that have duplicate names, to ensure isolation of one meaning from another (prevent name clashes).
Going a little "deeper:" we can view NameSpaces as an abstraction of an underlying code base that involves Assemblies; see this to explore this further: [^]
C# allows multiple NameSpaces in one file; other languages (ex. Java) do not.
It is very typical to use 3rd. party tools, or code libraries (dll's), and typical that you need to import code which will have their own NameSpaces. In C# Visual Studio you do this from the Solution/Project/References/Add Reference menu in the Solution Explorer.
Then, you enable the imported code to become available by adding a 'using statement with the name of the NameSpace. Member 12974235 wrote: Public Partial Class MainWindow:Window This is the default declaration of a newly created WPF app.Quote: <global.microsoft.visualbasic.compilerservices.designergenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form This what the Designer.vb file in a VB app uses.Quote: public partial class Form1 C# declaration.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Namespaces: Dave and Bill have covered that comprehensively.
public partial class MainWindow:Window (Note that I corrected your typecase: C# is case sensitive, and "public", "partial", and class" are keywords, "Public", "Partial", and "Class" are not so you would get compilation errors with your original code).
public says that the class can be used inside and outside the containing class or namespace: if I reference your Assembly file once you have built it, I can use your class in my code.
partial you know about.
MainWindow:Window You are declaring a class: public partial class starts that, and MainWindow gives it a name. Without a name, you couldn't create an instance of the class which means you (pretty much) can't use it at all. The colon character ':' tells the compiler that this class called MainWindow is derived from an existing class - in this case the base class is called Window . This is called inheritance and you will meet this later in your course or book as it is very much fundamental to C# (and in fact to all OOPs languages). For the moment, just think of it as saying "MainWindow is a Window and I need to specify that if anything is going to work" - inheritance is one of three very important class "attributes" that you will need to learn, probably together, and they are all rather too complicated to cover in a little text box like this!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
modified 10-Jul-19 3:27am.
|
|
|
|
|
fyi: my students have responded well to the idea of a "library of blueprints," where you check out a Class (or, whatever) blueprint (declaration), and build it (instantiation). using this metaphor, you can describe the internal components (Fields, Properties, etc.) of a Class declaration as a "bill of materials and/or required tools, building skills).
mmmm ... what would a language running in .NET be without its own syntax ? a carnival ride with no admission fee ?
i'm grateful that the abomination of 'let has not snuck in to C#'s pantry, except in that execrable dialect of LINQ. :omg for that, i'll put up with the Elvis operator (#6), and new weirdness' in pattern matching now marching towards us (#7, #8).
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
APL, I suspect!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Just the sight of the three letters "APL" gives me an immediate cold chill: I was in the first year of a doctoral program at UC Berkeley (long ago, as in the early '80's), and the required research component for the year ... which was supposed to make us masters of statistical inference, wizards of qualitative social science research, etc. ... was taught by a person who decided we (the doctoral students) should grok all his lectures that he chalkboarded using APL. None of us had any prior programming experience ... remember this is back in punch-card jobs and terminals connected to mainframe days; you had to go over to a building to get your print out.
The amount of mental bandwidth I wasted pretending the teaching and the APL was intelligible ! I quit the program at the end of the first year: having stuck it out to prove I was not a "quitter."
Interestingly enough, a year later I got deep into Lisp, and assembly language.
Perhaps I should thank APL for curing me of an academic career ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I know the feeling - I was working for a Terminal manufacturer, just before the advent of the PC and they bought an APL company (they made APL interpreters if I recall correctly). So they wanted a APL terminal, which meant I had to sit down with these guys and work out what they actually needed. Took forever to get it all up and running on a Z80 (with 8K RAM and 32K ROM) but it worked pretty well, I think. Don't think we actually sold any, or at least I never got a single bug report ...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You programmers seem to think and speak in the most peculiar, esoteric terms I've ever heard in my life.
|
|
|
|
|
Nah, we actually make sense when you understand the terms - just there is a lot of complexity and a need to be precise about what we are saying so there are a lot of technical terms.
Compare that with doctors, where the technical terms are there to make it hard for non-medical staff to understand: "Clavicle" for "Collar bone"; "Sphenopalatine ganglioneuralgia" - "ice cream headache"; "Synchronous diaphragmatic fluttering" - "Hiccups"; "Sternutate" - "Sneeze"; "Borborygmi" - "Tummy rumbles"; "Horripilation" - "Goose bumps"; and so on ... they aren't there to make things any clearer!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Perhaps one day you'll take a course in Computer Science.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Name spaces help to avoid "name collisions" when you start creating "solutions" that have multiple "classes", in multiple "projects". A "console app" can easily wind up becoming something "bigger" where the benefits of name spaces become more obvious.
Besides allowing one to "split" a "partial" class across multiple source files, partial classes also allow you to "extend" a 3rd party or "generated" source code (class) file without modifying the original. (e.g. Entity Framework "entity" classes)
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
xlApp.Workbooks.Open(filePath, 0, false, 2, " ", " ", false, XlPlatform.xlWindows, " ", true, false, 0, true,
xlWorkSheet = (Worksheet)xlWorkBook.Worksheets.get_Item(1));
System.Runtime.InteropServices.COMException: 'Exception from HRESULT: 0x800A03EC'
Thank You in Advance for your kind consideration
|
|
|
|
|
This code won't even compile. You're making an assignment in an argument being passed to Open. That's not going to work.
Also, are you opening a password protected workbook? You're supplying a password, a space character, when opening the workbook. That is NOT the same as leaving the password parameter as empty or having "no value".
You didn't specify what type of app you're writing, Windows Forms, Windows Service, WPF, ASP.NET, MVC, ... Yes, it matters. You cannot use Excel interop in a web application, like ASP.NET or MVC, or a Windows Service app.
|
|
|
|
|
Yes Thank You! I also was wondering about the password parameter! Your information is helpful and Thank You for your Time
|
|
|
|
|
hello!!!! my C# code is not going on i have some difficulties to write on my database(postgresql with pgadmin4) this is my code please help me
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Npgsql;
using NpgsqlTypes;
using WindowsFormsApplication1.Beans;
namespace WindowsFormsApplication1
{
public partial class inscription : Form
{
public static Client client;
DateTime date;
string Conx = "Server=localhost;Port=5432;Database=postgres;User=postgres;pwd=yannick93";
NpgsqlCommand MyCmd = null;
NpgsqlConnection MyCnx = null;
public inscription()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void b_annuler1_Click(object sender, EventArgs e)
{
}
private void b_confirm1_Click(object sender, EventArgs e)
{
String nom = esp_nom.Text;
String prenom = esp_prenom.Text;
String adr = esp_adr.Text;
String ville = esp_ville.Text;
String pass = esp_pass.Text;
String confirm = esp_conf.Text;
if (nom == "" || prenom == "" || adr == "" || ville == "" || pass == "" || confirm == "")
{
MessageBox.Show("veuiller entrer tous les parametres", "parametres manquants");
}
else
{
if (!pass.Equals(confirm))
{
MessageBox.Show("veuillez bien saisir votre mot de pass", "erreur de confirmation");
}
else
{
Connexion connect = new Connexion();
try
{
date = DateTime.Now;
String dateh = date.ToShortTimeString();
String datej = date.ToShortDateString();
var tabh = dateh.Split(':');
var tabj = datej.Split('/');
String h = tabh[0];
String m = tabh[1];
String j = tabj[0];
String mois = tabj[1];
String an = tabj[2];
String dnom = nom.Substring(0, 1);
String id = "dif-" + dnom + h + m + j + mois + an;
client = new Client(id, nom, prenom, adr, ville, pass);
string insert = "INSERT INTO client(id,nom,prenom,adr,ville,pass) values('" + client.id + "','" + client.nom + "','" + client.prenom + "','" + client.adr + "','" + client.ville + "','" + client.pass + "')";
MessageBox.Show("erreur d'accessibilite 2", "error2");
NpgsqlCommand MyCmd = connect.con.CreateCommand();
MyCmd.CommandText = insert;
MessageBox.Show("erreur d'accessibilite3", "error3");
MyCmd.ExecuteNonQuery();
MessageBox.Show("erreur d'accessibilite4", "error4");
connect.con.Close();
MessageBox.Show(dateh, datej);
}
catch (Exception)
{
MessageBox.Show("erreur d'accessibilite", "error");
}
}
}
}
public void InsertPersons(string nom, string prenom, string tel, string adresse)
{
MyCnx = new NpgsqlConnection(Conx);
string insert = "INSERT INTO \"client\"(id,nom,prenom,adr,ville,pass) values(:id,:nom,:prenom,:adr,:ville,:pass)";
MyCnx.Open();
MyCmd = new NpgsqlCommand(insert, MyCnx);
MyCmd.Parameters.Add(new NpgsqlParameter("id", NpgsqlDbType.Varchar)).Value = client.id;
MyCmd.Parameters.Add(new NpgsqlParameter("nom", NpgsqlDbType.Varchar)).Value = nom;
MyCmd.Parameters.Add(new NpgsqlParameter("nom", NpgsqlDbType.Varchar)).Value = nom;
MyCmd.Parameters.Add(new NpgsqlParameter("prenom", NpgsqlDbType.Varchar)).Value = prenom;
MyCmd.Parameters.Add(new NpgsqlParameter("tel", NpgsqlDbType.Varchar)).Value = tel;
MyCmd.Parameters.Add(new NpgsqlParameter("adresse", NpgsqlDbType.Varchar)).Value = adresse;
MyCmd.ExecuteNonQuery();
MyCnx.Close();
}
}
}
this my error
<pre>A first chance exception of type 'System.InvalidOperationException' occurred in Npgsql.dll
The thread 'vshost.RunParkingWindow' (0x338) has exited with code 0 (0x0).
The thread '<No Name>' (0x1658) has exited with code 0 (0x0).
The program '[7312] WindowsFormsApplication1.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[7312] WindowsFormsApplication1.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
|
|
|
|
|
run the debugger and inspect the string "insert" and see if you can run that directly using one of the postgresql clients. This will most likely identify the issue.
Also read up on sql injection attacks as you are inviting someone to destroy your database.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
The annoying thing is that he has already copy'n'pasted the code to avoid SQL Injection elsewhere without understanding what the heck he is doing or why...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
PLEASE i do not understand well what you are saying
|
|
|
|
|
Quote: read up on sql injection attacks as you are inviting someone to destroy your database.
What that means is this: never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
i doont no how to run the debugger
|
|
|
|
|
Then learn!
The debugger is the biggest, badest, best tool in your box: chances are you will spend more time using that than you will your editor - even when you get more experience - because as you advance, so your code becomes more complex, and testing and diagnosing problems also becomes more complicated.
So find out how to use the debugger, and start finding your problems. Judging by the amount of HTML there is stuffed into your sample, you are using VS Code, so start reading here: Debugging in Visual Studio Code[^]
If you aren't, then start here: Navigate code with the debugger - Visual Studio | Microsoft Docs[^]
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|