[英]How to pull data from a SQL Query based on data/id relationship. Using ASP.net WebMatrix
I'm using ASP.net WebMatrix 我正在使用ASP.net WebMatrix
I have a sql query which looks like this: 我有一个SQL查询,看起来像这样:
var queryformdata = db.Query("SELECT * FROM document_data WHERE doc_id = @0", 1534);
doc_id field_data field_name
---------- ---------- ----------
1534 John f_name
1534 61st Street f_address
And input fields which look like this: 并输入如下所示的字段:
<input type="text" id="f_name" name="f_name" value="" />
<input type="text" id="f_address" name="f_address" value="" />
I want the value of "John" to appear for f_name and "61st Street" to appear for f_address 我希望为f_name显示“ John”的值,并为f_address显示“ 61st Street”的值
I know the value of field_data, but don't know how to pull that from the query without doing a separate query for every input field. 我知道field_data的值,但不知道如何在不对每个输入字段进行单独查询的情况下从查询中提取该值。 I found a C# function called .Select() but can't get it to work. 我发现了一个名为.Select()的C#函数,但无法正常工作。 Here is what I tried: 这是我尝试过的:
@{
DataRow[] foundRows;
foundRows = queryformdata.Select("field_name LIKE 'f_name'");
}
<input type="text" id="f_name" name="f_name" value="@foundRows.field_data" />
That gives me the error: Compiler Error Message: CS0411: The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. 那给了我错误:编译器错误消息:CS0411:方法'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable,System.Func)'的类型参数无法从用法中得出。 Try specifying the type arguments explicitly. 尝试显式指定类型参数。
Can someone help me figure out how to make this work. 有人可以帮我弄清楚如何进行这项工作。
Thanks 谢谢
Instead of: 代替:
@{
DataRow[] foundRows;
foundRows = queryformdata.Select("field_name LIKE 'f_name'");
}
Try this: 尝试这个:
@foreach(var queryformdata = db.Query("SELECT * FROM document_data WHERE doc_id = @0", 1534)) {
<input type="text" id="@queryformdata.field_name" name="@queryformdata.field_name" value="@queryformdata.field_data" />
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.