技术开发 频道

使用C++Builder2007连接C#开发的WebService方法[一]


【IT168技术文档】

  1:建立VS2005 WebService项目

  代码中序列化自定义类
[Serializable] public struct UserInfo{ public string username; public string password; };
  撰写Webservice方法:
[WebMethod] public UserInfo GetAUserByID(string username) { UserInfo ui = new UserInfo(); string sql = "select username,password from UserInfo where username='"; sql += username; sql += "'"; try { sqlConnection.Open(); //SQLCMD.CommandText = sql; SqlDataAdapter adapter = new SqlDataAdapter(sql,sqlConnection); //adapter = SQLCMD.ExecuteReader(); DataSet ds = new DataSet(); adapter.Fill(ds); ui.username = ds.Tables[0].Rows[0]["username"].ToString(); ui.password = ds.Tables[0].Rows[0]["password"].ToString(); //sda. } catch { } finally { sqlConnection.Close(); } return ui; }
0
相关文章