服务器端向mysql数据库写数据

using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.OleDb;
using System.Drawing;
using System.Data;
using MySQLDriverCS;
using System.Web.Script.Serialization; namespace GLSXJSON2.Controllers
{
public class AdviseInsertController : Controller
{ public string Index(string text) //这里的text是从service文件中获取的参数
{
MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("localhost", "glsx", "root", "ecust2016", ).AsString);
conn.Open(); //这几句为建立一个MySQL的连接conn //sql语句写成string形式
string str0 = string.Format("select MAX(Id) from fag order by Id desc"); int id;
MySQLCommand cmd0 = new MySQLCommand(str0, conn); //建立MySQL执行命令cmd0 参数为str0和conn
if(cmd0.ExecuteScalar()!=null&&!Convert.IsDBNull(cmd0.ExecuteScalar())){//执行查询操作,ExecuteScalar()返回查询结果第一行
id=int.Parse(cmd0.ExecuteScalar().ToString())+; //这是不为空情况把id+1
}
else
id=; //若为空id置0 //sql语句写成string形式
string str = string.Format("insert into fag(Id,content) values({0},'{1}')", id, text); try
{
MySQLCommand cmd = new MySQLCommand(str, conn); //建立MySQL执行命令cmd 参数为str和conn
cmd.ExecuteNonQuery(); //返回执行的条数
return ""; //执行成功返回1
}
catch
{
return "-1"; //失败返回-1
} } }
}

服务器端从mysql数据库读数据

 using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.OleDb;
using System.Drawing;
using System.Data;
using MySQLDriverCS;
using System.Web.Script.Serialization; namespace GLSXJSON2.Controllers
{
public class OrderController : Controller
{ public JArray Index(string value,string id)
{
MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("localhost", "glsx", "root", "ecust2016", ).AsString);
conn.Open();
//sql语句写成string形式
string str = string.Format("select placetime,price,cloth11,cloth12,cloth13,cloth14,cloth21,cloth22,cloth23 from `order` where status='{0}' and customer='{1}'", int.Parse(value),int.Parse(id)); //用conn连接数据库然后执行sql语句生成datatable
MySQLDataAdapter sda = new MySQLDataAdapter(str, conn);
DataTable dt = new DataTable();
sda.Fill(dt);//填充数据到dt //创建一个用以序列化的对象
JavaScriptSerializer jss = new JavaScriptSerializer();
//从datatable中逐列获取值到数组
System.Collections.ArrayList dic = new System.Collections.ArrayList();
foreach (DataRow dr in dt.Rows)
{
System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
foreach (DataColumn dc in dt.Columns)
{
drow.Add(dc.ColumnName, dr[dc.ColumnName]);
}
dic.Add(drow);
}
conn.Close(); //将获取到的数列序列化以后转化为string然后再转化为JArray
return JArray.Parse(jss.Serialize(dic));
} }
}

服务器端cs文件的更多相关文章

  1. WPF根据Oracle数据库的表,生成CS文件小工具

    开发小工具的原因: 1.我们公司的开发是客户端用C#,服务端用Java,前后台在通讯交互的时候,会用到Oracle数据库的字段,因为服务器端有公司总经理开发的一个根据Oracle数据库的表生成的cla ...

  2. aspx文件、aspx.cs文件、aspx.designer.cs文件之讲解

    .aspx文件:(页面)书写页面代码.存储的是页面design代码.只是放各个控件的代码,处理代码一般放在.cs文件中. .aspx.cs文件:(代码隐藏页)书写类代码.存储的是程序代码.一般存放与数 ...

  3. HTML控件ID和NAME属性的区别,以及如何在asp.net页面的.CS文件中获得.ASPX页面中HTML控件的值

    在html中:name指的是用户名称,ID指的是用户注册是系统自动分配给用户的一个序列号. name是用来提交数据的,提供给表单用,可以重复: id则针对文档操作时候用,不能重复.如:document ...

  4. asp.net WebForm程序删除.designer.cs文件之后的故事

    1.介绍 正常情况下添加一个WebForm程序结构如下(命名为:myWebForm.aspx) 文件说明:.aspx文件:书写html代码部分,以及javascript,css等代码书写及引用 .as ...

  5. 从java文件和CS文件里查询方法使用次数工具

    前几天,领导让我找一下老系统(Java)里getRemoteUser方法都哪个文件用了,package是什么,方法被调用了多少次,当时因为着急,所以,直接人工找的,但是以后要是再出现,人工找就太讨厌了 ...

  6. C# 调用WebService的3种方式 :直接调用、根据wsdl生成webservice的.cs文件及生成dll调用、动态调用

    1.直接调用 已知webservice路径,则可以直接 添加服务引用--高级--添加web引用 直接输入webservice URL.这个比较常见也很简单 即有完整的webservice文件目录如下图 ...

  7. 关于MVC中Start.cs文件的作用

    当我们建立默认的 .NET Framework4.5.2框架下的Web  MVC 应用程序后,调试过程中我发现在程序启动页面加载完成会执行一段代码,这段代码让人有点摸不着头脑,因为之前完全没见过,调试 ...

  8. vs2010边调试边编辑后台.cs文件的办法

    方法一:在web项目的属性页里的web标签页,选中“启用编辑并继续”项 方法二:菜单 工具+选项+调试+编辑并继续,选中“启用编辑并继续”项. 设置完之后,调试web项目的时候可以直接修改.cs文件, ...

  9. 如何把.cs文件编译成DLL文件

    开始--程序--Microsoft Visual Studio.NET 2013--Visual Studio.NET工具,点击其中的"VS2013 开发人员命令提示",就会进入M ...

随机推荐

  1. 数学图形(1.18)Poinsot's spiral螺线

    它是一种螺线,其特点是细分时无限递归. 相关软件参见:数学图形可视化工具,使用自己定义语法的脚本代码生成数学图形.该软件免费开源.QQ交流群: 367752815 vertices = t = *PI ...

  2. SWIG 快速入门

    SWIG 安装 本文使用了 SWIG 版本 2.0.4(参见 参考资料 获取下载站点的链接).要构建和安装 SWIG,可按照典型的开源安装流程,在命令提示符下输入以下命令: 请注意,为前缀提供的路径必 ...

  3. 如何获得Windows Server 2012上的FC的WWN

    我有一个测试环境, 一对Host与storage array之间既有iSCSI的连接, 也有FC的连接. 原来iSCSI的连接是OK的, 现在需要转用FC. 当在光纤交换机上划好了Zone之后, st ...

  4. [C++基础]那些容易被混淆的概念:函数/数组指针-指针函数/数组,类/函数模板-模板类/函数

    函数指针-指针函数 函数指针的重点是指针.表示的是一个指针,它指向的是一个函数.eg: int (*pf)(); 指针函数的重点是函数.表示的是一个函数,它的返回值是指针.eg: int* fun() ...

  5. 用php当作cat使用

    今天,本来是想敲 node test.js 执行一下,test.js文件,结果 惯性的敲成了 php  test.js, 原文输出了 test.js的内容. 突然觉得,这东西 感觉好像是 cat  命 ...

  6. C# 怎么显示中文格式的星期几

    1.DateTime.Now.ToString("dddd",new System.Globalization.CultureInfo("zh-cn")); 2 ...

  7. RS中的关系引用不明确以及行列自动添加了追溯

    问题1:由于在FM模型的物理层是自己新建了查询主题,查询主题采用对已经存在的表进行sql处理然后重命名, 使用的是sql类型的数据源,sql类型设置的查询类型是默认的cognos类型,而语法是本地的结 ...

  8. Elasticsearch 数据搜索篇

    curl 'localhost:9200/_cat/indices?v' health index pri rep docs.count docs.deleted store.size pri.sto ...

  9. [Transducer] Step by Step to build a simple transducer

    Transducers are composable algorithmic transformations. They are independent from the context of the ...

  10. itext处理pdf

    http://www.java2s.com/Tutorial/Java/0419__PDF/DecryptPdffile.htm