MySql的基本语法,以及一些常见的WebService配置

1、MySql的基本语法

一、建立数据库

create database DB;
复制代码

二、建立表

值得一提的是,mysql中bool类型用tinyint(1)来表示,1是真,0是假mysql

create table Class
(
  Id int primary key auto_increment,
  Name varchar(20) not null,
);
create table UserInfo
(
  Id int primary key auto_increment,
  Name varchar(20) not null,
  Sex tinyint(1) default'0',
  ClassId int,
  foreign key (ClassId) references Class(Id)
);
复制代码

三、添加数据

insert into Class (Name) values ('1709A');
insert into UserInfo (Name,Sex,ClassId)values('张三',1,1)
复制代码

四、删除数据

delete from UserInfo ;
delete from UserInfo where Id =1;
复制代码

五、查询数据

select * from UserInfo
select a.`Name`,b.`Name` from UserInfo a inner join Class b on a.ClassId=b.Id
复制代码

六、修改数据

update UserInfo set Name='李四' where Id =1;
update UserInfo set Name='李四',Sex=0 where Id =1;
复制代码

ADO.NET( MySql链接 )

一、连接字符串

"Database=BookDB;Data Source=localhost;User Id=root;Password=******;charset='utf8';pooling=true"web

二、和sqlserver的没啥区别,就是加了mysql几个字

WebService的Ajax跨域配置

一、web.config 节点下添加如下内容:

<system.web>
   <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
        <add name="HttpSoap"/>
        <add name="Documentation"/>
      </protocols>
    </webServices>
  </system.web>
  
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/>
        <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type"/>
        <add name="Access-Control-Allow-Origin" value="*"/>
      </customHeaders>
    </httpProtocol>
  </system.webServer>
复制代码

**ajax

2.正确地编写webserivce的代码

若要容许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService]sql

三、 ajax访问WebService使用Post方式请求,而且规范数据内容为utf-8

$.ajax({
            url: ''
            , type: 'post ,contentType: "application/json;utf-8" ,dataType:'json' , success: function (d) { console.log(d) } }) 复制代码
相关文章
相关标签/搜索