我从别人继承了这一项目,并需要清理,以满足新的要求,另一个表中提取数据 - 他们已经设计了它,像这样..INSERT INTO表由
我在访问2个表数据库(我已经包括在大括号中的字段的数据类型):
活动:
事件ID {自动编号} | EventTitle {短文本} | EventDescription {长文本} | EventDate {Date/Time} | EventCategory {查找与类别的排源/ CategoryTitle}
分类:
类别ID {自动编号} | CategoryTitle {短文本} | CategoryImage {短文本} | CategoryColor {Short Text}
'Categories'表包含关于特定类别的所有'Master'信息,例如名称,图标(例如刻度线,十字等)。
而且我有一个查询(访问内部)这两个表中的数据拉在一起,下面的字段顺序:
事件ID | EventTitle | EventDescription | EventDate | CategoryTitle | CategoryImage
该查询的SQL是:
SELECT Events.EventID, Events.EventTitle, Events.EventDescription,
Events.EventDate, Categories.CategoryTitle, Categories.CategoryImage,
Categories.CategoryColor FROM Events INNER JOIN Categories ON
Events.EventCategory = Categories.CategoryID ORDER BY
Events.EventDate;
网站的其他领域依赖查询检索信息。
在Visual Studio中,我试图从插入文本框的ASP值和下拉控件到从我的数据库下面的字段:
- EVENTTITLE(以Events.EventTitle)
- EventDescription(以Events.EventDescription )
- EVENTDATE(至Events.EventDate)
- EventCategory(至Events.EventCategory)
编号4是有问题的,因为它目前是对“主”事件表的访问查找,该表包含有关实际类别的信息。据推测,从未打算将数据以这种方式插入表中;设置事件类别的唯一可能方式是使用Access数据库内的下拉组合框来选择事件。
最后这里是子程序我写插入到数据库:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString)
conn.Open()
Dim cmd As New OleDbCommand("INSERT INTO Events (EventTitle, EventDescription, EventDate, EventCategory) VALUES (@f1,@f2,@f3,@f4)",
conn)
cmd.Parameters.AddWithValue("@f1", tb_eventtitle.Text)
cmd.Parameters.AddWithValue("@f2", tb_eventdescription.Text)
cmd.Parameters.AddWithValue("@f3", DateTime.ParseExact(tb_eventdate.Text, "dd/MM/yyyy",
CultureInfo.InvariantCulture))
cmd.Parameters.AddWithValue("@f4", dd_eventcategory.SelectedValue)
cmd.ExecuteNonQuery()
conn.Close()
End Sub
还有其他ASP.NET databinded上依赖于的“类别”的内容,网站的其他控制表格保持不变,所以我怎么能插入'事件'表与我上面列出的字段(特别是 EventCategory)?
编辑:
这里是我完成的子:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString)
conn.Open()
Dim cmd As New OleDbCommand("INSERT INTO Events (EventTitle, EventDescription, EventDate, EventCategory) VALUES (@f1,@f2,@f3,@f4)",
conn)
cmd.Parameters.AddWithValue("@f1", tb_eventtitle.Text)
cmd.Parameters.AddWithValue("@f2", tb_eventdescription.Text)
cmd.Parameters.AddWithValue("@f3", DateTime.ParseExact(tb_eventdate.Text, "dd/MM/yyyy",
CultureInfo.InvariantCulture))
cmd.Parameters.AddWithValue("@f4", dd_eventcategory.SelectedIndex + 1)
cmd.ExecuteNonQuery()
conn.Close()
End Sub
'EventCategory'查找字段是否允许多个选择? – 2013-04-10 19:18:09
@Gord Thompson:不,只有单一选择,即“公开”,“私人”或“仅限群组” – adaam 2013-04-10 19:20:35
@dasblinkenlight:对不起,这是一个错误,我会重新发布我的工作代码(我只是玩弄选择多个表,但意识到我的问题的解决方案将需要比简单地执行选择查询更多的工作) – adaam 2013-04-10 19:24:40