|
Hi guys,
I create a formular in my .js file.I create a mysql databes with navicat 8 editor.I wanna that when i enter my data in the formular and click in the save button,it will be saved in the database.For that,in my .aspx.cs file i have this code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Odbc;
public partial class application_Application : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
switch (this.Request ["Action"])
{
case "SaveData":
{
string nom = this.Request ["Name"];
string CIN = this.Request ["CarteIdentité"];
string Mat = this.Request ["Matricule"];
string ConnectionString= "Driver={MySQL ODBC 3.51 Driver};"
+ "Server=localhost;" + "Database="informations";" + " UID=root;" + "PASSWORD=root";
OdbcConnection conn=new OdbcConnection(ConnectionString);
string requete=??????
OdbcCommand ODC=new OdbcCommand(requete,conn);
OdbcDataReader ODR;
conn.Open();
ODR=ODC.ExecuteReader();
ODR.Close();
conn.Close();
}break;
default:{}break;
}
}
}
my problem is how i will write in "string requete= " to send the information to my database table
Ty for u help
|
|
|
|
|
Your query will be look like the following:
string requete="INSERT INTO TableName(Column1, Column2, column3)
VALUES('" + nom +"', '" + CIN + "', '" + Mat +"')";
and then finally
ODR=ODC.ExecuteNonQuery();
Hope this helps
|
|
|
|
|
Hi Umair,
I tried u solution.It runs me an error"informations doesn't exist in the current context",informations is the name of my database"
my mysqlconnexion string is:
string ConnectionString= "Driver={Navicat 8 for MySQL};"
+ "Server=localhost;" + "Database="+informations+";" + " UID=root;" + "PASSWORD=root";
Also the
ODR=ODC.ExecuteNonQuery(); u tell me to add,what is its utility?where can I place it?
ty
|
|
|
|
|
Umair Feroze is correct, but I would strongly recommend you use a parametrised query instead of adding the string together:
string requete="INSERT INTO TableName(Column1, Column2, column3) VALUES(@NOM, @CIN, @MAT)";
...
ODC.Parameters.Add("@NOM", nom);
ODC.Parameters.Add("@CIN", CIN);
ODC.Parameters.Add("@MAT", Mat); Particularly with a web based application, there is a high risk of an deliberate or accidental SQL Injection attack which non-parametrised queries are wide open too.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Hi Pierre as OriginalGriff suggested you a perfect way to save data in MYSQL i will also suggest you to use Parametrized query against database(MYSQL)
you can take a look there[^] and there[^] to learn how to use parametrized query to prevent SQL Injection Attack.
|
|
|
|
|
Is it possible, without wierd try to open the file and if failed sleep a while then try again or sleep after create event 30 seconds to make sure large file is copied, wait for file copy completion event?
It fires event too soon before the file is completely copied.
Чесноков
|
|
|
|
|
I assume you´re talking about some kind of service on the receiving machine?
For situations like this, I don´t hook into the "creation" event, I use the "rename" event. First copy, then rename -> your watcher sees it
I cannot remember: What did I before google?
|
|
|
|
|
no, I have to catch when large file is copied into the folder, e.g. 0.5-1Gb
Чесноков
|
|
|
|
|
I've done some extsnsive FileSystemWatcher work (check this article series - part 2 is especially interesting[^]). It it were me, I'd wait for the created event, and then start a thread that tried to achieve an exclusive open on the file in question. Once that is achieved, the copy process is most likely finished.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
You have to use a Windows API function call to check for the operation to be completed (or you can spin in managed code catching exceptions). After all, in the MS world no one writes to a file to the subsequently use said file.
|
|
|
|
|
I tend to use a second, very small file, which creates/writes/closes in a jiffy after the huge file has been processed. Then the FSW has to watch the small file only.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Something to ponder. What effect would the kernel transaction manager have here?
|
|
|
|
|
Just to be clear, there is no "completion event". The FSW tells you when a file is CREATED, not when a copy operation is going on.
A file copy operation is just an application (Explorer) opening one file for read and another file for write. Read the bytes from one file and write them to another.
The FSW cannot tell what is going on with the files.
But, yeah, your code has to respond to the Created event from the FSW, then start trying to open the file for read with exclusive access (ShareDenyAll). If the open statement fails, wait for a few seconds, then try it again. When you finally get the file open, your copy operation should be done. Close the file and process to do whatever you wanted with the file.
|
|
|
|
|
Hello,
trying to build a Windows programm, I 've declared an object in Fornm1.cs by typing
Person[] P = new Person[10];
after a class Person I 've created on another file called Person.cs
Then on the function that is being activated after clicking on a button inside the Form I pass simple numerical values to a member attribute like below:
private void btnObjectAdd_Click(object sender, EventArgs e)
{
lbltest_i.Text = i.ToString();
P[i] = new Person();
P[i].category = i;
i++;
if (i == 10)
{
for (i = 0; i < 10; i++)
P[i] = null;
i = 0;
}
}
Thus I get P[0]=0, P[1]=1, ... P[9]=9.
Then I try to call a value of an object on another function like
private void showToolStripMenuItem_Click(object sender, EventArgs e)
{
int value = P[2].category;
}
and I get value = 2.
This works perfect.
But if I change
int value = P[2].category;
into
int value = P[i].category;
then I get an error that I should create an object with 'new'.
Variable i is declared as
int i = 0;
outside the functions but inside the
public partial class Form1 : Form
Is that the problem?
modified on Monday, February 7, 2011 1:14 PM
|
|
|
|
|
There seems to be something very wrong with your design. But if "i" is declared in the same class as your showToolStripMenuItem_Click code then there should be no reason why that is the problem. Perhaps you need to post more of your code - and please you the PRE tags to format is more readably.
return 5;
|
|
|
|
|
Thanks for the 'pre' tip, i was looking for s'thing like that.
I got rid of the confusing 0 by changing the array into
new Person[11] instead of a 10 dimension. After all, we 've got plenty of memory nowdays
As a result everything worked fine! It must have been some other mistake, as the one I thought of.
|
|
|
|
|
How is it possible to make a dynamic system so that everytime a new setting is added to the app.config file, the system can take that into consideration?
For example, my present system, looks in the app.config file and gets the value of a key i.e.
<add key="AllowedTime" value="5"/>
<add key="MyValue" value="10"/>
and the system does checks based on this figures. For example if the retrieved value i.e. 5 is less than the MyValue in the app.config file...
I can go on and add more settings in the app.config file and add the logic to the c# code, but I wonder if there is a generic way so that as long as the setting is entered in such a manor so that the c# code can analyse that without me adding to the c# code each time there is a new setting in the config file.?
What do you think?
Thanks
|
|
|
|
|
Just a quick thought. There may be built in functionality for this kind of thing I don't know of...
<add key="NumberOfValues" value="3"/>
<add key="MyValue1" value="1"/>
<add key="MyValue2" value="2"/>
<add key="MyValue3" value="3"/>
Then in code...
int count = int.Parse(ConfigurationManager.AppSettings["NumberOfValues"]);
for(int i = 1; i <= count; i++)
{
string setting = ConfigurationManager.AppSettings["MyValue" + i];
}
...of course, it depends what you actually plan on doing with these kind of values. I have not needed this functionality before and I imagine the closest thing I would need would probably result in me creating an XML file of some sort
return 5;
|
|
|
|
|
Before doing anything with the settings, you can call the Load() method on the settings object to make sure you're using the latest settings, or you can setup a thread that watches the file, and reloads it when the file changes, or even setuup a thread that loads it every X minutes.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
how to create own DB emails to used in own messenger
|
|
|
|
|
Nope, sorry.
I understand all of the individual words.
It's just the whole sentence that makes no real sense.
Please, try to give us more information on what problem you are having.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
the problem is create db
this db contains emails that will
used i messenger how to create email
in this db and how make email appear
as offline and online to other members
|
|
|
|
|
I'm sorry, I can't understand your question.
N2 @ <= 77K & > 63K.
|
|
|
|
|
Keith Barrow wrote: N2 @ <= 77K & > 63K.
I'm sorry, I can't understand your question.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
Abut you do know the correct answer, at least around here
|
|
|
|