评论我有events
表,其中包括这么多的cols除了Id
PK
和表Comments
,其中包括text
,eventId
和Id
PK。
我该如何选择事件信息,它是一条单独的sql语句中的注释,如何使用它以及它应该是什么样的!
如何选择每行
注意事件ID(评论)= ID(事件)
评论我有events
表,其中包括这么多的cols除了Id
PK
和表Comments
,其中包括text
,eventId
和Id
PK。
我该如何选择事件信息,它是一条单独的sql语句中的注释,如何使用它以及它应该是什么样的!
如何选择每行
注意事件ID(评论)= ID(事件)
嗯,这应该去做...
SELECT * FROM events
INNER JOIN comments on comments.eventid = events.id
如果您不需要的所有列是很好的做法,只选择列你真的需要。
SELECT Id, eventId FROM events
INNER JOIN comments on comments.eventid = events.id
来提取它在你的C#代码,你可能做到这一点System.Data
风格:
using (SqlConnection connection = new SqlConnection("Put your ConnectionString here"))
{
connection.Open();
using (SqlDataAdapter adapter = new SqlDataAdapter("My SQL from Above", connection))
{
DataTable table = new DataTable();
adapter.Fill(table);
// now you can do here what ever you like with the table...
foreach(DataRow row in table.Rows)
{
if (row.IsNull("Text") == false)
Console.WriteLine(row["Text"].ToString());
}
}
}
我需要知道如何使用和提取它(每个事件都有很多评论) – Rawhi 2010-08-15 13:53:06
我会用以下语句:
SELECT e.Id, c.Id, c.text
FROM events e
INNER JOIN Comments c ON e.Id = c.EventId
你说的“如何意味着什么用它'?你有使用这些数据的应用程序吗?什么样的应用程序?什么编程语言? – 2010-08-15 13:55:04
我正在使用C#... – Rawhi 2010-08-15 13:57:12