【发布时间】:2009-10-02 13:05:55
【问题描述】:
我正在尝试将 3 个文本框绑定到一个类,该类检索 3 个文本框中每一个的任何先前存储的记录。我不知道如何从面向对象的角度从一个类中检索 3 个不同的值。我知道如何返回单个字符串、布尔值等变量,但一次不超过 1 个。
我使用的简单 bool 返回方法示例,如何调整它以返回 3 个单独的字符串变量 - 代码片段:
public static Boolean isQuestionnaireComplete(string strHash)
{
SqlConnection con = Sql.getConnection();
try
{
SqlCommand cmd = new SqlCommand("SELECT IsComplete FROM UserDetails WHERE Hash='" + strHash + "' AND IsComplete=1");
cmd.Connection = con;
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
da.Fill(dt);
if (dt.Rows.Count == 0)
{
return false;
}
else
{
return true;
}
}
catch
{
//TODO:log error
return false;
}
finally
{
con.Close();
}
}
ASPX 代码段:
<asp:TextBox runat="server" ID="txt1" Height="200px" Width="600px"></asp:TextBox>
<asp:TextBox runat="server" ID="txt2" Height="200px" Width="600px"></asp:TextBox>
<asp:TextBox runat="server" ID="txt3" Height="200px" Width="600px"></asp:TextBox>
【问题讨论】: