我想从我的数据库中获取数据到我的标签。
这是我的代码:
con = new SqlConnection(conS);
try
{
con.Open();
string q = "SELECT SearchTerm FROM Sentiment WHERE Sentiment = 'positive'";
SqlCommand query = new SqlCommand(q, con);
using (SqlDataReader dr = query.ExecuteReader())
{
bool success = dr.Read();
if (success)
{
// Label1.Text = dr.GetString(1);
label3.Text = dr.GetString(1);
}
}
con.Close();
}
catch (Exception ex)
{
label3.Text = "Error";
}
但是,当我运行该应用程序时,我的标签显示错误'。这段代码有什么问题?
提前谢谢你:)
答案 0 :(得分:1)
尝试使用选择查询获取Apple::Apple(Apple const & anotherApple)
{
// allocate an array to hold pointers to Node
array = new Node*[tableSize];
for(int i=0; i<tableSize; i++)
{
Node* src = anotherApple.array[i];
Node* dest;
if (src == NULL)
{
array[i] = NULL;
continue; // no data to copy, continue to next row
}
// set array[i] since there is at-least one element
dest = new Node;
dest->data = src->data;
array[i] = dest;
src = src->next;
while(src != NULL)
{
Node* n = new Node;
dest->next = n;
dest = n;
dest->data = src->data;
src = src->next;
}
dest->next = NULL;
}
}
记录。
Top 1
和
string q = "SELECT TOP 1 SearchTerm FROM Sentiment WHERE Sentiment = 'positive'";
希望它会有所帮助。