|
When the query is work will call an insert query but when it is fail will appear a message that the record didn't founded in database
|
|
|
|
|
And what is your question? I can't see one in there at all.
|
|
|
|
|
when the query is false how can i take the result so i can use it for doing something else with this
|
|
|
|
|
What query? How is it returning false? You haven't shown a query.
|
|
|
|
|
OleDbConnection dbConnDest;
dbConnDest = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= SystemA.accdb");
string query_select = "SELECT ReferenceYear FROM [MS Access;DATABASE=" + dialog.FileName +"].Questionnaires_Table1 Where ReferenceYear = '" + dateref.Text + "';";
OleDbCommand cmd_year = new OleDbCommand(query_select, dbConnDest);
dbConnDest.Open();
string rfyear = cmd_year.ExecuteScalar().ToString();
|
|
|
|
|
So all you're doing is testing to see if ReferenceYear exists? Why not just do SELECT Count(1)... instead, and then just evaluate the count? If it's zero, the record doesn't exist? Also, you may want to pay attention to the fact your select statement is vulnerable to a SQL Injection attack.
|
|
|
|
|
Exactly true..
KiranKumar Roy
|
|
|
|
|
ok i make a class and i have there the following code:
public DataTable findrefyear(string dateref)
{
try
{
//Set the access command string
string query_insert = "INSERT INTO Questionnaires_Table (BranchName,Factor,Region,Branch_ID,[Current_Date],No_Employees,"
+ "No_Cashdesk,UrbanArea,TouristArea,RuralArea,GreenLinearArea,CentralStreets,EscapeBack,Collonization,"
+ "TimeDelay,PatrolPolice,Visibility,SafeBoxRisk,StaffAccess,KeyboardActiviation,ConnectionKSC,GSMCommunicator,SystemAlarmRisk,"
+ "InstalledSKKT,CheckSKKT,CheckDesk,CheckEntrance,SKKTRisk,RenovatedStore,MetalCashDrawers,ExtensionCash,Limits,"
+ "CashDrawers,CasherRisk,WarningAlert,SecurityWarningDelay,WarningRisk,BothSideDoors,"
+ "DoorsSound,ExitRisk,EmergencyCase,RobberyCase,DescriptionForm,SeminarRobbery,EducationRisk,ReferenceYear) "
+ "SELECT BranchName,Factor,Region,Branch_ID,Current_Date,No_Employees,"
+ "No_Cashdesk,UrbanArea,TouristArea,RuralArea,GreenLinearArea,CentralStreets,EscapeBack,Collonization,"
+ "TimeDelay,PatrolPolice,Visibility,(TimeDelay+PatrolPolice+Visibility)/3,StaffAccess,KeyboardActiviation,ConnectionKSC,GSMCommunicator,(StaffAccess+KeyboardActiviation+ConnectionKSC+GSMCommunicator)/4,"
+ "InstalledSKKT,CheckSKKT,CheckDesk,CheckEntrance,(InstalledSKKT+CheckSKKT)/2,RenovatedStore,MetalCashDrawers,ExtensionCash,Limits,"
+ "CashDrawers,(CheckDesk+CheckEntrance+RenovatedStore+MetalCashDrawers+ExtensionCash+Limits+CashDrawers)/7,"
+ "WarningAlert,SecurityWarningDelay,(WarningAlert+SecurityWarningDelay)/2,BothSideDoors,"
+ "DoorsSound,(BothSideDoors+DoorsSound)/2,"
+ "EmergencyCase,RobberyCase,DescriptionForm,SeminarRobbery,(EmergencyCase+RobberyCase+DescriptionForm+SeminarRobbery)/4,ReferenceYear "
+ "FROM [MS Access;DATABASE=" + dialog.FileName + "].Questionnaires_Table1 Where ReferenceYear = '" +dateref + "';";
//create new new access connection to the database
OleDbConnection conn = new OleDbConnection(ConnectionString);
//create new access data adapter
OleDbDataAdapter oleDBAdapter = new OleDbDataAdapter(query_insert, conn);
//create new access command builder
OleDbCommandBuilder oleDBBuilder = new OleDbCommandBuilder(oleDBAdapter);
dTable = new DataTable();
oleDBAdapter.Fill(dTable);
conn.Close();
}
catch (OleDbException e)
{
MessageBox.Show(e.ToString());
}
//return the search results on a datatable
return dTable;
}
Also i have in appropriate form the following code that call the query when it is work:
dbConnDest.Open();
DataTable find_data = importrefyear.findrefyear(dateref.Text);
if (find_data.Rows.Count >= 1)
{
"How i CAll the query from here???"
}
Also the SELECT Count(1)is the above method i use ??
|
|
|
|
|
What is the result of a query in c# when is false or is true
for example i have the following query and i want to do something when is false. How i manage this?
string rfyear = ((string)cmd_year.ExecuteScalar());
i want to manage with "if" if i can to do something like this...
if (rfyear.Length == 0) { MessageBox.Show("the query is false "); }
else{ MessageBox.Show("OK");
textBox1.Text = rfyear;
|
|
|
|
|
It all depends on what your query is actually returning: it is very possible that your line:
string rfyear = ((string)cmd_year.ExecuteScalar()); Will not work, but throw an InvalidCastException because the data coming back can't be cast to a string - it may work if you change it to:
string rfyear = cmd_year.ExecuteScalar().ToString(); But...I wouldn't recommend it as there is a very good chance that you will get a string containing the name of the type of the value returned.
What does your query return when it works and when it fails?
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
I just came to know about the Linux tracing tool mechanism available in Java (LTTng - Linux Tracing Toolkit Next Generation).
It actually is a framework that provides analysis of traces and events on a linux machine.
I want to develop a windows application which will read linux traces(usually in CTF format - common Trace Format) from a file and decode the value and time of trace. This application runs on Windows PC.
Can any body suggest me the best possible approach for this?
|
|
|
|
|
If I were looking to do this, I'd first of all look to see if anyone had already written code that did this; if they hadn't, I'd then look at the specifications[^].
|
|
|
|
|
I've made an application that works with SQL database. Now want without install the software SQL on client computer ,an applicationto work.
what way do you suggest?
|
|
|
|
|
Use a different database, like SQLite. SQL Server must be on the client computer, or the client computer must be able to connect to the SQL server remotely, it doesn't run without the back-end installed on something that it can talk to.
|
|
|
|
|
Ron Beyer wrote: or the client computer must be able to connect to the SQL server remotely, it doesn't run without the back-end installed on something that it can talk to.
Thanks for the Answer
Can you explain more about connecting remotely, step by step
Thanks...
|
|
|
|
|
|
I think you are not talking about web application. In web application DB will setup in SQL server. For a desktop application sql server is not a recommended DB. You have setup SQL server in client machine also for desktop app
|
|
|
|
|
manu v nath wrote: For a desktop application sql server is not a recommended DB. Yes, it is. As soon as multiple users need access to the data, we use a real database-server. A local database-file (SQLite, MSAccess) is only recommended if the data remains local and doesn't need to be shared.
manu v nath wrote: You have setup SQL server in client machine also for desktop app No, one has to install Sql Server. The client only needs access to the server-application. That might be a server that's shared among multiple clients as well as a local server that's only used locally.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
For the installation of a C# desktop 2010 application, I am using the traditional setup and deployment template.
As part of this template, I want to make certain that a folder is created in a directory path that looks like
C:\log_files.
Thus can you tell me how to have the setup and deployment project create the directory path for me, if the directory path does not exist?
|
|
|
|
|
I'm not sure about VS2010 as I am still using VS2008, however in the setup project, open the primary output file and click on the 'File System on Target Machine'. There you can add a 'Custom Folder' through the right-click menu. Name the new folder whatever you want, and then click on properties for the new folder and set the default location to the directory path you want to use.
Having said that, if this is a folder that your application is going to use during runtime, I would highly recommend that your application check for the existence of the folder and create it if needed before writing the "log files" to it (see the System.IO.Directory class). For instance, will your application crash if after it is installed the user then deletes the "log files" folder?
Also, keep in mind that not all users may have permissions to create folders on the C:\ drive. I've run into that issue with Windows7 several times and the permissions we use. You may need to come up with a work-around or use a user's folder instead.
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
Hi All,
I created a ClickOnce application, but if I upload it to download sites, they sometimes have problems processing it. For example, they install (copy) the .application file instead of running it.
So what I want to do, is create a ClickOnce application downloadable from my website, and apart from that build an installer around it so it can also be installed via an .msi.
After installing I would like it to behave like a ClickOnce application, that is autmatically checking and updating from the website.
However, I do not know all the ins and outs of both technologies, so I don't know if this is possible.
Any help or suggestions would be nice.
Thanks in advance,
Mathijs Beentjes.
|
|
|
|
|
You could always avoid ClickOnce altogether and serve the files via an automatic update facility - Application Auto-update via Online Files in C#[^]
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hi experts,
a software I made provides the user with a PropertyGrid[^] to change certain values. Some of them are enum-based.
Customer doesn't like to be forced to click twice: first to open the UITypeEditor[^], second to choose the value.
Customer would rather want to have possible values constantly displayed as RadioButton[^]s. (See this illustration[^].)
Is PropertyGrid that customizable to draw a property as something other than $PropertyName and $PropertyValue as one-line-texts?
Is there some OwnerDraw possibility I didn't recognize?
Is there a third-party control that supports that (this[^] looks nice but User still has to pull the editor down)?
Ciao,
luker
|
|
|
|
|
lukeer wrote: Customer doesn't like to be forced to click twice
There's an example on a fully custom inline editor in one of the CodeProject articles[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
But it still shows a value as one line. At least I haven't found a way to create multi-line visualizations of multiple-choice options.
Ciao,
luker
|
|
|
|
|