vs2013 C# webapi Mysql新手,求各位大神指导
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了vs2013 C# webapi Mysql新手,求各位大神指导,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2612字,纯文字阅读大概需要4分钟。
内容图文
connectionStrings> <!--<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20150910132908;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication1-20150910132908.mdf" />--> <add name="MySQLConnString" connectionString="Server=localhost;Port=3306;Database=products;Uid=root;Pwd=" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
添加MySql辅助类,mysqlHelper
name和下文的System.Configuration.ConfigurationManager.AppSettings相同
/This connectionString for the local test public static readonly string connectionStringManager = System.Configuration.ConfigurationManager.AppSettings["MySQLConnString"]; //ConfigurationManager.ConnectionStrings["MySQLConnString"].ConnectionString; //hashtable to store the parameter information, the hash table can store any type of argument //Here the hashtable is static types of static variables, since it is static, that is a definition of global use. //All parameters are using this hash table, how to ensure that others in the change does not affect their time to read it //Before ,the method can use the lock method to lock the table, does not allow others to modify.when it has readed then unlocked table. //Now .NET provides a HashTable‘s Synchronized methods to achieve the same function, no need to manually lock, completed directly by the system framework private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
已经可以使用mysql
var strConn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MySQLConnString"].ConnectionString; MySqlCommand cmd = new MySqlCommand(); using (MySqlConnection conn = new MySqlConnection(strConn)) { conn.Open(); }
感谢海洋教我。
执行select语句
var strConn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MySQLConnString"].ConnectionString; MySqlCommand cmd = new MySqlCommand(); using (MySqlConnection conn = new MySqlConnection(strConn)) { conn.Open(); MySqlCommand mycmd = new MySqlCommand("insert into product(name,price) values(‘小王‘,‘11‘)", conn); MySqlCommand objCmd = new MySqlCommand("select * from `product` ", conn); MySqlDataReader r = objCmd.ExecuteReader(); int i = 0; while (r.Read()) { try { products[i].Id = r.GetInt32(0); products[i].Name = r.GetString(2); products[i].Price = r.GetInt32(1); i++; } catch { } } conn.Close(); }
发布
新建配置文件
ok
引用请注明http://www.cumt.top/blog/?p=107
vs2013 C# webapi Mysql新手,求各位大神指导
标签:
本文系统来源:http://www.cnblogs.com/cumt/p/4815455.html
内容总结
以上是互联网集市为您收集整理的vs2013 C# webapi Mysql新手,求各位大神指导全部内容,希望文章能够帮你解决vs2013 C# webapi Mysql新手,求各位大神指导所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。