C#高级编程:会议登记 Web服务
2009-04-14 08:25:04 来源:WEB开发网 [WebMethod]
public int AddEvent(String eventName, String eventRoom,
String eventAttendees, String eventDate)
{
}
下面声明访问数据库、连接数据库以及执行查询时需要的对象,完成这些工作所使用的代码与PCSWebApp3中的代码相似(此外,这里也需要连接字符串,但是并没有给出):
[WebMethod]
public int AddEvent(String eventName, String eventRoom,
String eventAttendees, String eventDate)
{
System.Data.OleDb.OleDbConnection oleDbConnection1;
System.Data.OleDb.OleDbDataAdapter daEvents;
DataSet ds;
oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
oleDbConnection1.ConnectionString = @" ... ";
String oleDbCommand = "INSERT INTO Events (Name, Room, AttendeeList," + " EventDate) VALUES ('" + eventName + "', '" + eventRoom + "', '" + eventAttendees + "', '" + eventDate + "')";
System.Data.OleDb.OleDbCommand insertCommand =
new System.Data.OleDb.OleDbCommand(oleDbCommand,
oleDbConnection1);
oleDbConnection1.Open();
int queryResult = insertCommand.ExecuteNonQuery();
}
更多精彩
赞助商链接