我有可变长度的字符数据,并希望存储在SQL Server(2005)数据库中.我想学习一些关于如何选择TEXT SQL类型或选择VARCHAR SQL类型的最佳实践,以及性能/覆盖/功能的优缺点.
其中[CastleType]在SQL Server中设置为数据类型"text",查询为:
SELECT *
FROM [Village]
WHERE [CastleType] = 'foo'
Run Code Online (Sandbox Code Playgroud)
我收到错误:
TEXT和VARCHAR数据类型在等于运算符中不兼容.
我是否可以使用WHERE子句查询此数据类型?
我试图empname从employeeTable 访问数据,但我写的代码给了我以下错误:
数据类型text和varchar在equal运算符中不兼容.
请提出解决方案
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string Connection = "Data Source=(local);Initial catalog=Test;Integrated Security=true";
string Query = "SELECT * FROM EmployeeTable WHERE empname='" + comboBox1.Text + "' ;";
SqlConnection conn = new SqlConnection(Connection);
SqlCommand cmd = new SqlCommand(Query, conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
textBoxEmpName.Text = reader["EmpName"].ToString();
}
}
Run Code Online (Sandbox Code Playgroud)