thanks i solve my c# problem :)
User3490
Posts
-
c# error -
double.tryparse()i have the code
string query_BranchExposureFactor = "SELECT BranchExposureFactor FROM Questionnaires_Table where Branch_ID = (SELECT Branch_ID FROM [MS Access;DATABASE=" + dialog.FileName + "].Questionnaires_Table1 Where ReferenceYear = '" + txtdateref.Text + "');";
OleDbCommand cmd_BranchExposureFactor = new OleDbCommand(query_BranchExposureFactor, dbConnDest);double branchExposureFactor = (double)(cmd_BranchExposureFactor.ExecuteScalar());
i have error with double so i want to use double.tryparse() but i think that i make something wrong how can i use it in the following code ?
double branchExposureFactor = (double)(cmd_BranchExposureFactor.ExecuteScalar());
-
C# Multiple connectionstringso how can i get data from access databases that has the same fields but with different content and i want to get data that have the same reference year from them every time i make import a file to a c# program without locally connect the database so with this way i have always updated data because i see what i want without have in mind the old data that has every access file that i use. i want only the records with the same reference year e.x with year 2013 how i manage this? one solution i find now is to make restore the access db file so i have always updates data :)
-
c# errorthe content of connection string is a access database file that i don't want to locally connect with my c# because it is updated every time and user can import to the program with reference year the records that associated with this year i try to make it locally connected in c# and i observe that the database does not updated when i make it import again from my desktop on my laptop so the database that it is locally connected to my c# program has old record in spite of the two file it is the same but on different locations (locally- desktop and the other can be import to c#) . i use the following query to get the records with the associated reference year but i have the problem that i said previous : public DataTable findref2(string refyear) { try { //create new new connection to the database OleDbConnection conn = new OleDbConnection(connectionstringA); //Set the command string string Cmd = ("SELECT ReferenceYear FROM Questionnaires_Table1 Where ReferenceYear = '" + refyear + "' "); //create new data adapter OleDbDataAdapter Adapter = new OleDbDataAdapter(Cmd, conn); //create new command builder OleDbCommandBuilder sqlCmdBuilder = new OleDbCommandBuilder(Adapter); dTable = new DataTable(); Adapter.Fill(dTable); conn.Close(); } catch (OleDbException e) { MessageBox.Show(e.ToString()); } //return the search results on a datatable return dTable; } how can i get data without make my database locally connected in my c# program and i have the possibility to get data when i import from anywhere on my laptop to c# program. i have already a form that i put the reference year and opened a window that i can choose the access db file and i can import to my c# program (because i move on my locally connected access database which is different from database i make import ) but only if the year i put previous is on access db file i choose. Now i try to make a select query to check if the reference year already exists on file but i have the error No database specified in connection string or IN clause maybe because i must make locally connection on c# but i don't want as i said previous. can you help me please?
-
C# Multiple connectionstringwhy i have the error no database specified in connection string or in clause i make the same steps that i make with my previous connection with access db and connection string
-
C# Multiple connectionstringcan i have 2 connection string and two connections in 2 different databases because i have an error that say no database specified or IN clause
-
c# errori change my code now and looks like the following: now i have 2 connectionstring in c# and 2 connection with 2 different access database in this query i use only one access db and one connection string but when i run the program it appears an error that say that No database specified in connection string or IN clause. what is the problem ? public bool findrefyear( string refyear) { bool findyear = false; //create new new access connection to the database OleDbConnection connd = new OleDbConnection(connection2); //Set the access command string OleDbCommand Cmd = new OleDbCommand("SELECT ReferenceYear FROM Questionnaires_Table1 Where ReferenceYear = '" + refyear + "';", connd); try { connd.Open(); Cmd.ExecuteNonQuery(); connd.Close(); findyear = true; } catch (OleDbException e) { MessageBox.Show(e.Message.ToString()); } i call the above code with this code: ----------------------------------------- ... if (txtdateref.Text != "" ) { bool find_data = qhandler.findrefyear(txtdateref.Text); if (find_data == false) { MessageBox.Show(" the record is not here ", "", MessageBoxButtons.OK); } else{ MessageBox.Show(" the record is here ", "", MessageBoxButtons.OK); } }
-
c# errori have 2 connectionstring in c# and 2 connection with 2 different access database in this query i use only one access db and one connection string but when i run the program it appears an error that say that could not found file dbfile.accdb what is the problem ? public bool findrefyear( string refyear) { bool findyear = false; //create new new access connection to the database OleDbConnection connd = new OleDbConnection(connection2); //Set the access command string OleDbCommand Cmd = new OleDbCommand("SELECT ReferenceYear FROM Questionnaires_Table1 Where ReferenceYear = '" + refyear + "';", connd); try { connd.Open(); Cmd.ExecuteNonQuery(); connd.Close(); findyear = true; } catch (OleDbException e) { MessageBox.Show(e.Message.ToString()); } i call the above code with this code: ----------------------------------------- ...
if (txtdateref.Text != "" )
{bool find\_data = qhandler.findrefyear(txtdateref.Text); if (find\_data == false) { MessageBox.Show(" the record is not here ", "", MessageBoxButtons.OK); } else{ MessageBox.Show(" the record is here ", "", MessageBoxButtons.OK); }
}
-
c# errorok
-
c# errorOleDbConnection 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 = '" + txtdateref.Text + "';"; OleDbCommand cmd_year = new OleDbCommand(query_select, dbConnDest); dbConnDest.Open(); string rfyear = cmd_year.ExecuteScalar().ToString(); if (rfyear == null) { MessageBox.Show(" file not found with this ref year ", "", MessageBoxButtons.OK); } dbConnDest.Close(); i have error in following row string rfyear = cmd_year.ExecuteScalar().ToString(); if the query is wrong appears the error: ------------------------------------------ Object reference not set to an instance of an object.
-
c# errorstring query_BranchExposureFactor = "SELECT BranchExposureFactor FROM Questionnaires_Table where Branch_ID = (SELECT Branch_ID FROM [MS Access;DATABASE=" + dialog.FileName + "].Questionnaires_Table1 Where ReferenceYear = '" + txtdateref.Text + "');";
OleDbCommand cmd_BranchExposureFactor = new OleDbCommand(query_BranchExposureFactor, dbConnDest);double branchExposureFactor = (double.TryParse()) (cmd\_BranchExposureFactor.ExecuteScalar().ToString());
i have error to the following code
double branchExposureFactor = (double.TryParse()) (cmd_BranchExposureFactor.ExecuteScalar().ToString());
-
c# errorthe user must input to the form a reference year and must choose an access file that the program have to take some record from this file with this reference year and add to another access file with insert query but sometimes maybe the user choose a year that does not be in access file. How can i verify that when the query has return null will must return a message to the user that the year that has enter does not exist in access file ?? yes dialog.FileName and txtdateref.Text has the appropriate values.
-
c# errordouble branchExposureFactor = ((double)cmd_BranchExposureFactor.ExecuteScalar());
the error is in above row but i didn't know what is the solution for this error :
Object reference not set to an instance of an object.
-
c# errori have the following code that appears an error
string query_BranchExposureFactor = "SELECT BranchExposureFactor FROM Questionnaires_Table where Branch_ID = (SELECT Branch_ID FROM [MS Access;DATABASE=" + dialog.FileName + "].Questionnaires_Table1 Where ReferenceYear = '" + txtdateref.Text + "');";
OleDbCommand cmd_BranchExposureFactor = new OleDbCommand(query_BranchExposureFactor, dbConnDest);double branchExposureFactor = ((double)cmd\_BranchExposureFactor.ExecuteScalar());
the error is : ---------------- Object reference not set to an instance of an object.
-
c# and query resultok 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;DAT
-
c# and query resultok 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;DAT
-
c# and query resultOleDbConnection 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();
-
c# and query resultwhen the query is false how can i take the result so i can use it for doing something else with this
-
c# and query resultWhen 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
-
c# and query resultWhat 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;