与Windows窗体C#连接的MySQL问题 [英] mysql problem to conect with windows form c#

查看:91
本文介绍了与Windows窗体C#连接的MySQL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有连接SQL的代码,我知道该怎么做.但是我对mysql有问题.对于Sql,我使用了此连接字符串

< configuration>
< configsections>

< connectionstrings>

< add name ="Aplikacion.Properties.Settings.dbBIBLOTEKAConnectionString">
connectionString ="Data Source = BESART-ARSENAL \ SQLEXPRESS; Initial Catalog = dbBIBLOTEKA; Integrated Security = True"
providerName ="System.Data.SqlClient"/>





然后我不知道在Data =>中做什么.在c#many中添加新的数据源.
然后是代码e.x的一部分,我在mysql中有文本框"name"和文本框"surname"以及带有两个列NAME和SURNAME的表.我想将windowos中我的应用程序中的数据发送到Mysql表.

I have code to connect with SQL and I know how to do it. But I have problem with mysql. For Sql I used this connection string

<configuration>
<configsections>

<connectionstrings>

<add name="Aplikacion.Properties.Settings.dbBIBLOTEKAConnectionString">
connectionString="Data Source=BESART-ARSENAL\SQLEXPRESS;Initial Catalog=dbBIBLOTEKA;Integrated Security=True"
providerName="System.Data.SqlClient" />





Then I dont know what to do in Data=> add a new data sourc in c# many.
and then the part of code e.x I have text box "name" and textt box "surname" and table in mysql with two colums NAME and SURNAME. I want to send data from my applicaton in windwos from to Mysql table.

推荐答案

您应该先做一些家庭作业.阅读以供参考.
.

或者只是
You should do some homework first. Read this for your reference.
Or this.

Or just Google it.
This is rather familiar topic.


Data Source = ServerName;初始目录=数据库名称;用户ID = yourid;密码=您的密码

如果您的sql服务器使用Sql Server身份验证进行连接,则用户ID和密码适用.
如果您的sqlserver使用Windows身份验证进行连接,则不需要用户ID和密码......
试试这个...
希望它能正常工作
Data Source= ServerName; Initial Catalog=databasename; user id=yourid;password=yourpassword

user id and password is applicable if your sql server connect with Sql Server Authentication
if your sqlserver connect with windows authentication than user id and password is not require...........
Try this...
I hope it will be work


您需要一个mysql连接器 http: //dev.mysql.com/downloads/connector/net/1.0.html [ MySqlConnection conn = null;
试试
{
conn = new MySqlConnection(connString);
conn.Open();
MySqlCommand cmd =新的MySqlCommand(sql,conn);
MySqlDataAdapter adap =新的MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
dataGridView1.DataSource = ds.Tables [0];
}
catch(ex ex例外)
{
Console.WriteLine("Error" + ex);
}
终于
{
conn.Close();
}
}
you need a mysql connector http://dev.mysql.com/downloads/connector/net/1.0.html[^]

donload from here then add reference in project

add this line in Proj
using MySql.Data.MySqlClient;

private void Form1_Load(object sender, EventArgs e)
{
//Set up connection string
string connString = @" server = localhost;
database = sujeetdb;
user id = root;
password =12345; ";
//Set up query string
string sql = @" select * from login ";
MySqlConnection conn=null ;
try
{
conn = new MySqlConnection(connString);
conn.Open();
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
dataGridView1.DataSource=ds.Tables[0];
}
catch (Exception ex)
{
Console.WriteLine("Error " + ex);
}
finally
{
conn.Close();
}
}


这篇关于与Windows窗体C#连接的MySQL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆