[如果一門程序設計語言不支持數據庫操作的話,其很難在現在的世界中存活下來。C#語言提供了豐富的數據庫操作類庫,極大地方便了對數據庫的操作。在C#中,常用的有三種 訪問
1.C#中調用MYSQL數據庫時,我用的是MySQLDriverCS這個方法.
一般的查詢可以方便執
mysql自定義函數、[string dbPath = @"Data\dbTest.mdb";string db = Server.MapPath(dbPath);string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db;stri
String connStr, commStr;
DataSet ds; //數據集
BindingSource bs; //數據綁定源,注意是全局的變量
MySQL 函數?MySQLConnection myconn;
MySQLDataAdapter myadp;//數據適配器
connStr = "Data Source=myshiyandb;Password=110810;User ID=root;Location=localhost;Port=3306;Extended Properties=";//數據庫連接字符串
//myconn = new MySQLConnection(new MySQLConnectionString("localhost", "myshiyandb", "root", "110810").AsString);
MySQL for visual studio1.2.8,myconn = new MySQLConnection(connStr);
try
{
myconn.Open();//打開數據庫
concat函數。}
catch(Exception e)
{
MessageBox.Show(e.Message);
mysql if、}
//
ds = new DataSet();
commStr = "select * from table1;";
mysql,myadp = new MySQLDataAdapter(commStr , myconn); //適配器
myadp.Fill(ds,"table"); //將查詢到數據填充到數據集
bs = new BindingSource();
bs.DataSource = ds.Tables["table"];
mysql 日期函數、dataGridView1.DataSource = bs; //綁定DataGridView到DataSet
//shut
try
{
mysql從庫1062、myconn.Close();
}
catch(Exception e)
{
sql 1062、MessageBox.Show(e.Message);
}
2.但是在通過這種方法,改一下其中的sql語句,雖然程序執行了,但是記錄添加不到數據庫中;解決辦法
connStr = "Data Source=myshiyandb;Password=110810;User ID=root;Location=localhost;Port=3306;Extended Properties=";//數據庫連接字符串
//myconn = new MySQLConnection(new MySQLConnectionString("localhost", "myshiyandb", "root", "110810").AsString);
myconn = new MySQLConnection(connStr);
try
{
myconn.Open();//打開數據庫
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
string strInsert = null;
strInsert = " insert into " + "table1" + " values "
+ " ( "
+ "'" + tbxLuruName.Text + "'" + ", "
+ tbxLuruAge.Text
+ " ) ";
//---
commStr = strInsert;
MySQLCommand cmd = new MySQLCommand(commStr, myconn);
cmd.ExecuteNonQuery();
//myadp = new MySQLDataAdapter(commStr, myconn); //適配器
try
{
myconn.Close();
}
catch (Exception e3)
{
MessageBox.Show(e3.Message);
}
[一.啟動服務在已經配置環境變量的情況下,在命令行輸入net start mysql啟動MYSQL服務二.進入數據庫操作命令行mysql -u root -p三.創建數據庫創建數據庫基礎命令create dat
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态