Click here to Skip to main content
14,207,068 members
Rate this:
 
Please Sign up or sign in to vote.
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)
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

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)
private void Form1_Load(object sender, EventArgs e)
{ 
    tblversiontstcBindingSource.DataSource = db.version;

    tbllineinfotstcBindingSource.DataSource = db.lineinfo;            
}

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?
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 3:42am
v3

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



Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190612.1 | Last Updated 14 Feb 2014
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100