+ 3
Can somme one explaine me this " if (dt.row [0][0].tostring () == "this"){ console.write ("this")}
explanation
16 Respuestas
+ 3
if //just an if statement
dt.row //datatable row
dt.row[0][0] //first [0] is row index //second [0] is cel index
.tostring() //get the string value of dt.row[0][0]
== // is equal to
"this" // the string "this", in this case it is not the object
console.write("this") //write this to console.
So if the first cel of the first row of the datatable contains the text "this", the program wil print the text "this" to the console.
+ 2
For the backup part I would use a simple File copy
After that use
use a 2 SqlConnection to connect to the two databases
use a 2 SqlCommand to define your request "select * from tableX"
and a 2 SqlDataReader to read the data
Compare the value and set values if needed.
https://www.sololearn.com/Discuss/471763/how-to-use-database-in-c-application
+ 1
yes yes that is it. thank you very Much i now understand the situation
+ 1
Yes it is possible and there are different ways to do it.
What is you definition of backup ?
Just store raw data so you can restore it later
Or
in SQL terms create a .bak file
(not sure if Access is able to do that ?)
What do you want to achieve ?
+ 1
So you need a backup in a file ?
(sorry for asking again but I need to understand it)
Is it really neccesary to split the database ?
What if you can compare and update the five tables
without affecting the other six
Would that be sufficient ?
+ 1
A connection to a database
// Northwind.mdb is located in the c:\Data folder.
string connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ "c:\\Data\\Northwind.mdb;User Id=admin;Password=;";
Link :
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-code-examples#oledb
Get all rows (just from one table)
string constr = @"Data Source=.;Initial Catalog=test;Integrated Security=True";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlDataAdapter adpt = new SqlDataAdapter("select * from Items",con);
DataTable dt = new DataTable();
adpt.Fill(dt);
link : https://www.codeproject.com/Questions/353481/How-can-we-fill-data-table-in-sqlcommand
Modify the row
foreach(DataRow dr in table.Rows) // search whole table
{
if(dr["Product_id"] == 2) // if id==2
{
dr["Product_name"] = "cde"; //change the name
//break; break or not depending on you
}
}
Link : https://stackoverflow.com/questions/19629644/how-to-edit-a-row-in-the-datatable
If you only load the table you need to validate and modify the row that need to be changed, the other 5 a be left unchanged.
0
sneeze please i have another question please.
" do you think it is possible to backup 5 tables in your acess database, clear it, and later restore it. that is the logic. Is it possible?
0
To access a database in c# there are 3 methods.
1) microsoft.interop
2) sql, sql-connection and sql command and sql reader
3) datatable and data-adapter object
4) file copy the database mdb-file
0
yes i want to store complet table all columns and rows with their values and give a a name to the save table as "saved table " and then clear the present table. And be able to restore it any time when needed. The real situation is that; i want to compare two table. For example create a form that compare two datatable e.g "table 2017 & table 2018 "
0
ok sneeze. But file copy system copy the database or table. because i saw a tutorial where it copy the database with all the tables inside the database. but i just needed To saved a few 5 tables out of 11 tables without affecting the other 6 tables.
0
Just brainstorming with you.
You already have a datatable do you ?
Is the datatable appropriate storage for you or do you need the backup in file format ?
0
yes i have a datatable. i need a backup format.
0
yes that is better for me sneeze.
0
As you said, without affecting the other tables.
0
Thank you, I understand it now. Come back to you later
0
Ok thanks.