Click here to Skip to main content
15,504,830 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
hi,all my friends!

I am a new coder!

Recently,I found Entity Framework could easily manage database,but I didn't understand it.
I want to learn it,so I wrote a simple program to manage two tables in MySQL database.

I use VS2010.
Reference:Tutorial: Using an Entity Framework Entity as a Windows Forms Data Source[^]

MySQL tables:(Model1.edmx have these tables)
SQL
CREATE TABLE `lineinfo` (
	`STT` BIGINT(20) NOT NULL AUTO_INCREMENT,
	`Line` VARCHAR(50) NULL DEFAULT NULL,
	`IP` VARCHAR(50) NULL DEFAULT NULL,
	`Process` VARCHAR(50) NULL DEFAULT NULL,
	`Version` VARCHAR(50) NULL DEFAULT NULL,
	`user_ip` VARCHAR(50) NULL DEFAULT NULL,
	`user_datetime` DATETIME NULL DEFAULT NULL,
	PRIMARY KEY (`STT`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM

SQL
CREATE TABLE `version` (
	`STT` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
	`Process` VARCHAR(50) NULL DEFAULT NULL,
	`Version` VARCHAR(50) NULL DEFAULT NULL,
	`Path` VARCHAR(800) NULL DEFAULT NULL,
	`user_ip` VARCHAR(50) NULL DEFAULT NULL,
	`user_datetime` DATETIME NULL DEFAULT NULL,
	PRIMARY KEY (`STT`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM

My program code:
(I can change data in datagridview)
C#
private void Form1_Load(object sender, EventArgs e)
{ 
    tblversiontstcBindingSource.DataSource = db.version;

    tbllineinfotstcBindingSource.DataSource = db.lineinfo;            
}

C#
private void button_update_Click(object sender, EventArgs e)
{
    db.SaveChanges();
}


My questions:

1.db.SaveChanges();
This method can save two tables's changes,but i need separately save tables's changes,how to do?


2.datagridview show a part of table,user_ip and user_datetime are not in datagridview.
I want to change data in datagridview,then db.SaveChange(),upload IP and Time to user_ip and user_datetime at the same time.I don't know how to do?


3.How to use filter and order by in Entity Framework?
C#
if (this.comboBox_process.Text == "ALL")
{
    tblversiontstcBindingSource.DataSource = db.tblversion_tstc;
} 
else if(this.comboBox_process.Text == "IMEI")
{
    tblversiontstcBindingSource.DataSource = //? i need a method,filter(Process ='IMEI') data 
}


4.what is Settings.settings file?
I create a MyConnectionString(server=localhost;User Id=robot;password=tstcrobot;Persist Security Info=True;port=1081;database=robot) in Settings.settings file.
I don't know what it is useful?

5.I don't know how to run my program in other PC,if i use Entity Framework ?

Please help!
Thank you very much!
Posted
Updated 14-Feb-14 4:42am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900