C#高级编程:给数据库添加会议数据
2009-04-14 08:25:00 来源:WEB开发网submitButton_Click()事件处理程序目前从会议特性中组合了一个字符串,并在 reulstLabel控件中显示它。要给数据库添加一个会议,需要把创建出来的字符串重新格式化到一个SQL INSERT查询中,并执行它。
注意:为了把数据写入Access数据库,ASPNET用户(在默认情况下运行ASP.NET进程的账户)必须明确地拥有文件的写入许可。这可以使用Windows资源
下面的许多代码都是很熟悉的:
protected void submitButton_Click(object sender, System.EventArgs e)
{
if (this.IsValid)
{
String attendees = "";
foreach (ListItem attendee in attendeeList.Items)
{
if (attendee.Selected)
{
attendees += attendee.Text + " (" + attendee.Value + "), ";
}
}
attendees += " and " + nameBox.Text;
String dateString =
calendar.SelectedDate.Date.Date.ToShortDateString();
String oleDbCommand = "INSERT INTO Events (Name, Room, " +
"AttendeeList, EventDate) VALUES ('" +
eventBox.Text + "', '" +
roomList.SelectedItem.Value + "', '" +
attendees + "', '" + dateString + "')";
更多精彩
赞助商链接