本文介绍了列名无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 使用(SqlConnection connection = new SqlConnection(connectionString)) { string str = SELECT Department,Name FROM View_3 Where CompanyName = + Class1.Text1; dba.setDataReader(str); public SqlDataReader setDataReader( string sSQL) { SqlCommand cmd = new SqlCommand(sSQL,conn,transaction); cmd.CommandTimeout = 300 ; SqlDataReader rtnReader; rtnReader = cmd.ExecuteReader(); return rtnReader; } 解决方案 在不知道你的表格结构的情况下,很难确定精确的列,但是至少有一个查询中的列名与表中的列名不匹配: -Department -Name -CompanyName 此外,您永远不应该将值直接连接到SQL语句。这将使您对SQL注入,转换问题等持开放态度。而是使用 SqlParameter [ ^ using (SqlConnection connection = new SqlConnection(connectionString)) { string str = "SELECT Department,Name FROM View_3 Where CompanyName=" + Class1.Text1; dba.setDataReader(str); public SqlDataReader setDataReader(string sSQL) { SqlCommand cmd = new SqlCommand(sSQL, conn, transaction); cmd.CommandTimeout = 300; SqlDataReader rtnReader; rtnReader = cmd.ExecuteReader(); return rtnReader; } 解决方案 Without knowing your table structure, it's hard to pinpoint the exact column but either way at least one of the column names in your query does not match column names in your table:-Department-Name-CompanyNameAlso, you should never ever concatenate values directly to the SQL statement. This would leave you wide open to SQL injections, conversion problems and so on. Instead use SqlParameter[^] 这篇关于列名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 13:04