本文介绍了获取“无效的列名称”从数据库获取数据时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,



我在基于Windows的C#中进行简单的应用程序。



我是使用搜索文本框将数据从数据库提取到Listview。我的桌子是这样的: -





DNO NAME EDUCATION EMAIL PHONE



100 Steve MS [email protected] 123



当我在搜索文本框中输入DNO值100时,我成功获得了数据Listviw。但是,如果我将名称值Steve以及其他列值,那么我收到错误无效

列名Steve。



Sir这是我的Listview代码和表创建查询

private void Submit_Click(object sender,EventArgs e)

{SqlConnection objCon = new SqlConnection(Data Source = OM-PC ; Initial Catalog = master; Integrated Security = True);

SqlDataAdapter objAdapt = new SqlDataAdapter(select * from Place Where NAME =+ textBox1.Text.ToString(),

objCon); DataTable objDT = new DataTable();

objAdapt.Fill(objDT);

//现在初始化listview

//设置视图以显示详细信息。

listView1.View = View.Details;

//允许用户编辑项目文本。

listView1.LabelEdit = true;

//允许用户重新排列列。

listView1.AllowColumnReorder = true;

//选择时选择项目和子项目。

listView1.FullRowSelect = true;

//显示网格线。

listView1.GridLines = true;

//按升序排列列表中的项目。

// listView1.Sorting = SortOrder.Ascending;

//最后填写listview

for(int i = 0; i< objDT.Rows.Count; i ++)

{DataRow objDR = objDT.Rows [i];

ListViewItem listitem = new ListViewItem(objDR [NAME]。ToString()); listitem.SubItems.Add(objDR [ 教育]的ToString()); listitem.SubItems.Add(objDR [ 电子邮件]的ToString()); // listitem.SubItems.Add(objDR [Phone]。ToString()); listView1.Items.Add(列表项);




* CREATE TABLE PLACE(DNO INT NOT NULL,NAME VARCHAR(20),EDUCATION VARCHAR(10),EMAIL NVARCHAR (20),PHONE INT))





请帮助我。

Hi Team,

I am making simple application in Windows based C#.

I am extracting data from database to Listview using search textbox . My table like this :-


DNO NAME EDUCATION EMAIL PHONE

100 Steve MS [email protected] 123

When I put DNO value "100" in search textbox then I got data successfully in Listviw . However If I put Name value "Steve" as well as other column value then I got error "Invalid
Column Name Steve" .

Sir This is my Listview Code and Table Creation Query
private void Submit_Click(object sender, EventArgs e)
{ SqlConnection objCon = new SqlConnection("Data Source=OM-PC;Initial Catalog=master;Integrated Security=True");
SqlDataAdapter objAdapt = new SqlDataAdapter("select * from Place Where NAME="+ textBox1.Text.ToString(),
objCon); DataTable objDT = new DataTable();
objAdapt.Fill(objDT);
//now initialize listview
// Set the view to show details.
listView1.View = View.Details;
// Allow the user to edit item text.
listView1.LabelEdit = true;
// Allow the user to rearrange columns.
listView1.AllowColumnReorder = true;
// Select the item and subitems when selection is made.
listView1.FullRowSelect = true;
// Display grid lines.
listView1.GridLines = true;
// Sort the items in the list in ascending order.
// listView1.Sorting = SortOrder.Ascending;
//finally fill listview
for (int i = 0; i < objDT.Rows.Count; i++)
{ DataRow objDR = objDT.Rows[i];
ListViewItem listitem = new ListViewItem(objDR["NAME"].ToString()); listitem.SubItems.Add(objDR["Education"].ToString()); listitem.SubItems.Add(objDR["Email"].ToString()); // listitem.SubItems.Add(objDR["Phone"].ToString()); listView1.Items.Add(listitem); } }


* CREATE TABLE PLACE(DNO INT NOT NULL , NAME VARCHAR(20), EDUCATION VARCHAR(10), EMAIL NVARCHAR(20), PHONE INT ))


Please help me for this .

推荐答案

Quote:

列名无效

很明显,使用名称列,您必须提供一些其他错误的列名。



因此,请检查并更正查询。

It is quite clear that while querying table using value for Name Column, you must be providing some other wrong Column name.

So, check and correct the query.


这篇关于获取“无效的列名称”从数据库获取数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 02:32