|
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 System.Data.OleDb;
namespace EmployeeAttendanceRegister
{
public partial class SignIN : Form
{
public SignIN()
{
InitializeComponent();
}
public OleDbConnection GetsqlCon()
{
string connstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/game/Desktop/3rd year/2nd Semester/INYM 328/EmployeeAttendanceRegister/EmployeeAttendanceRegister/EmployeeAttendanceRegister.accdb";
OleDbConnection mycon = new OleDbConnection(connstring);
mycon.Open();
return mycon;
}
public void getComm(string connstring1)
{
OleDbConnection sqlcon = this.GetsqlCon();
OleDbCommand sqlcomm = new OleDbCommand(connstring1, sqlcon);
sqlcomm.ExecuteNonQuery();
sqlcomm.Dispose();
sqlcon.Close();
sqlcon.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string col1 = dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col2 = dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col3 = dataGridView1[2, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col4 = dataGridView1[3, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col5 = dataGridView1[4, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col6 = dataGridView1[5, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col7 = dataGridView1[6, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string insert_sql = "INSERT INTO Attendance(Username,Lastname,Firstname,Cellnumber,Officenumber,DepartmentName,Passwrd) VALUES('" + col1 + "','" + col2 + "','" + col3 + "','" + col4 + "','" + col5 + "','" + col6 + "','" + col7 + "')";
this.getComm(insert_sql);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|
|
|
|
First things first. Google for "SQL Injection Attack" to find out why building a SQL query string like you have is such a bad idea. I'll give you two hints: Security and Maintainability.
Then Google for "C# Access Parameterized Query" for what to do about it.
|
|
|
|
|
Alright thank you Dave I will.
|
|
|
|
|
"Username" is a reserved keyword[^], and a bad choice for a column-name. You'd have to escape it, probably by putting it in [username]. A better solution would be to rename the column.
You'd also want to be using "parameterizes queries" to prevent people like me from deleting everything in there. And instead of manually disposing, I'd recommend using a using clause.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
ya i agree
|
|
|
|
|
Thanks everyone for your responses,I managed to fix my code, now everything is fine.
|
|
|
|
|
hi
i have a problem in receive data from serial port in c# , i do`nt now why create this problem in my application .the error is :
ErrorDeviceApplication4.exe
NotSupportedExceptionControl.Invoke must be used to interact with controls created on a separate thread.at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)at System.Windows.Forms.Control.get_Text()System.Wind ows.Forms.Control.set_Text(String value)at DeviceApplication4.Form1.Port_DataReceived_1(Objec t sender,SerialDataReceivedEventArgs e)at System.IO.Ports.SerialPort.CatchReceivedEvents(Obj ect src, SerialDataReceivedEventArgs e)at System.IO.Ports.SerialStream.EventLoopRunner.CallR eceiveEvents(Objectstate)at System.Threading.ThreadPool.WorkItem.doWork(Object o) at System.Threading.Timer.ring()
|
|
|
|
|
As the error suggests, there is a problem since you are possibly trying to access the UI thread on the thread that is listening to the serial port.
Use BeginInvoke to access controls on the main thread.
|
|
|
|
|
i dont use thread in my application .
in your reply for post means i use thread in my application?
|
|
|
|
|
Yes, you are. Read the documentation on the DataReceived Event[^. From the MSDN documentation:
The DataReceived event is raised on a secondary thread when data is received from the SerialPort object. Because this event is raised on a secondary thread, and not the main thread, attempting to modify some elements in the main thread, such as UI elements, could raise a threading exception. If it is necessary to modify elements in the main Form or Control, post change requests back using Invoke, which will do the work on the proper thread.
|
|
|
|
|
I hosted my Web application project in IIS. When I used it in Integrated mode the form is not submitting, but it works fine in classic mode. I don't know why it behaving like this?. Is there any way to fix it?
In the screenshot images of the following link ( http://stackoverflow.com/questions/18831086/iis-hosted-site-not-working-properly-in-integrated-mode-but-working-fine-in-clas), i have represented the problems we faced. It's a big headache and we are trying for hours to solve this problem. Yet we didn't find any solution.
In the integrated mode as in the above, the action attribute of form element is "/" so that the form is not submitting to the right path.
Actually it has to be submitted to the causeprofile.aspx page but it didn't.
In the integrated mode it renders the form element with action attribute as "/". But in Classic mode it renders the form element with action attribute as "/causeprofile.aspx".
What is the difference between these?
Please kindly help me on this issue.
|
|
|
|
|
What does this have to do with C#?
Veni, vidi, abiit domum
|
|
|
|
|
|
Hi,
I am trying to work out the dates for the previous and next 2 Wednesdays and I just cannot work out how to do it...
So, for example, say today is 09/16/2013
I am trying to get
09/04/2013, 09/11/2013, 09/18/2013, 09/25/2013
I just cannot think what the way to do this is....
Can anyone help please?
Thanks
Trev
|
|
|
|
|
Create a DateTime [^] object and use the Day and DayOfWeek properties to get the relevant values.
Veni, vidi, abiit domum
|
|
|
|
|
Try this:
DateTime mondaySept162013 = new DateTime(2013, 9, 16);
DateTime wednesday;
for (int x = 2; x > -13; x = x - 7)
{
wednesday = mondaySept162013.AddDays(x);
Console.WriteLine(wednesday.DayOfWeek + " " + wednesday.ToShortDateString());
}
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
modified 16-Sep-13 14:06pm.
|
|
|
|
|
System.DateTime t = System.DateTime.Today ;
int sub = System.DayOfWeek.Wednesday - t.DayOfWeek ;
if ( sub > 0 ) sub -= 7 ;
System.DateTime lw = t.AddDays ( sub ) ;
System.DateTime twbt = lw.AddDays ( -7 ) ;
System.DateTime nw = lw.AddDays ( 7 ) ;
System.DateTime twat = nw.AddDays ( 7 ) ;
|
|
|
|
|
PIEBALDconsult wrote: System.DateTime twat
Veni, vidi, abiit domum
|
|
|
|
|
Thank you very much!
this is the solution I have used.
Trev
|
|
|
|
|
Hello,
I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads.
Now, if i run my application(with 25 threads) on my machine(with 4 logical processors),
Are those 25 threads run on single processor or all 4 logical processors?
Can any one help me please..
Thanks,
Srini
|
|
|
|
|
Srinivas P N V wrote: Are those 25 threads run on single processor or all 4 logical processors? Whatever Windows chooses (and that may vary!) It's the OS that's responsible for scheduling threads.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
if memory serves me correctly Task Class[^] and Parallel.ForEach[^] are optimised to handle the cores of a processor better than Threading class or threadpool .
But you haven't really given much information to help us give you a better answer.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
One logical processor can run one thread at a time - and this includes all the of system threads, as well as all the application threads in the machine - not just yours. So at any one time, four threads can be running at the same time, and one or more of these may be one of your 25. The system is at liberty to start threads on any processor available to it at the time it wants to switch threads - either because a thread has paused itself, ot run out of time slice and must wait to give other threads a chance.
You can't force a thread onto an processor, or even force a thread to run without interruption from beginning to end. So all 25 thread could run on the same processor, one after another, or they could be spread around - you have no influence over that, and cannot even tell which processor you are running on: or even if it was the same processor a microsecond ago!
Do be aware that if you start a number of threads to speed things up, you may infact slow things down due to locking and thread switching overheads - particularly if there aren't enough physical processors to run them all at the same time.
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
Quote: You can't force a thread onto an processor,
I'm not claiming any expertise on this subject and have no idea why one would wish to do this.
But couldn't you iterate through Process.GetCurrentProcess.Threads seeking the ProcessThread which has the ID equal to the ID returned from the API function GetCurrentThreadId (called on the thread in question).
Once you have the needed ProcessThread, you could set its processor affinity[^] property.
|
|
|
|