<connectionStrings> <add name="mysqlwxs" connectionString="server=192.168.0.200;user id=root;password=admin;database=wxs;CharSet=gb2312;" providerName="MySql.Data.MySqlClient"/> </connectionStrings> private string mysqlYunfeng = ConfigurationManager.ConnectionStrings["mysqlwxs"].ConnectionString; public FriendGPSList ReturnFriendGPSList(string groupId) { FriendGPSList gpsList = new FriendGPSList(); gpsList.gpsList = new List<GPSNode>(); gpsList.resNode = new ResErrorNode(); try { MySqlConnection conn = new MySqlConnection(mysqlYunfeng); conn.Open(); string selectStr = String.Format("select FID,FName,FTel,FSex,FGLatitude,FGLongitude,FGHight from friends where FGroupID = '{0}'",groupId); MySqlDataAdapter adapter = new MySqlDataAdapter(selectStr, conn); DataSet ds = new DataSet(); adapter.Fill(ds); DataTable dt = ds.Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { GPSNode node = new GPSNode(); node.FId = dt.Rows[i][0].ToString(); node.FName = dt.Rows[i][1].ToString(); node.FTel = dt.Rows[i][2].ToString(); node.FSex = dt.Rows[i][3].ToString(); node.Latitude = double.Parse(dt.Rows[i][4].ToString()); node.Longitude = double.Parse(dt.Rows[i][5].ToString()); node.Hight =Int32.Parse(dt.Rows[i][6].ToString()); gpsList.gpsList.Add(node); } } catch(Exception e) { gpsList.resNode.Code = -1; gpsList.resNode.Message = e.Message; gpsList.gpsList = null; return gpsList; } gpsList.resNode.Code = gpsList.gpsList.Count; gpsList.resNode.Message = "OK"; return gpsList; } public ResErrorNode AddGroup(string name, string pass, string adminId) { MySqlConnection conn = new MySqlConnection(mysqlYunfeng); conn.Open(); DateTime dt = DateTime.Now; string id = dt.ToString("MMddhhmmss"); string insertStr = String.Format("insert into Groups(GroupID,GroupName,GroupPass,GroupAdminId) values('{0}','{1}','{2}',{3})",id,name,pass,adminId); MySqlCommand cmd = new MySqlCommand(insertStr, conn); ResErrorNode resNode = new ResErrorNode(); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { String message = ex.Message; Console.WriteLine("插入失败:" + message); resNode.Code = -1; resNode.Message = message; return resNode; } resNode.Code = 0; resNode.Message = id; return resNode; }