gpt4 book ai didi

c# - 如何将字段绑定(bind)到文本框

转载 作者:太空宇宙 更新时间:2023-11-03 11:26:10 26 4
gpt4 key购买 nike

我需要将字段 (ComputerTag) 绑定(bind)到文本字段。

这是我的代码:

public void load() 
{
//Intializing sql statement
string sqlStatement = "SELECT Computertag FROM Computer WHER
ComputerID=@ComputerID";

SqlCommand comm = new SqlCommand();
comm.CommandText = sqlStatement;
int computerID = int.Parse(Request.QueryString["ComputerID"]);

//get database connection from Ideal_dataAccess class
SqlConnection connection = Ideal_DataAccess.getConnection();
comm.Connection = connection;

comm.Parameters.AddWithValue("@ComputerID", computerID);

try
{
connection.Open();
comm.ExecuteNonQuery();
//Bind the computer tag value to the txtBxCompTag Text box
txtBxCompTag.Text= string.Format("<%# Bind(\"{0}\") %>", "Computertag");

}
catch (Exception ex)
{
Utilities.LogError(ex);
throw ex;
}
finally
{
connection.Close();
}
}

但是 "txtBxCompTag.Text = string.Format("<%# Bind(\"{0}\") %>", "Computertag");"这行代码没有将值绑定(bind)到文本框。如何将值分配给文本框?

最佳答案

您可以使用 ExecuteReader

private static void CreateCommand(string queryString,
string connectionString)
{
using (SqlConnection connection = new SqlConnection(
connectionString))
{
connection.Open();

SqlCommand command = new SqlCommand(queryString, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}", reader[0]));
}
}
}

以上代码来自msdn:http://msdn.microsoft.com/en-us/library/9kcbe65k(v=vs.90).aspx

关于c# - 如何将字段绑定(bind)到文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9271531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com