Click here to Skip to main content
16,019,764 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 steve@gmail.com 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 .
Posted
Updated 26-Dec-13 1:02am
v2
Comments
Sergey Alexandrovich Kryukov 25-Dec-13 0:16am    
And your query is..?
—SA
Member 10272175 25-Dec-13 4:05am    
Sir I have given query below
Peter Leow 25-Dec-13 1:59am    
What you do not show we do not know. Show the relevant code.
Member 10272175 25-Dec-13 4:04am    
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 ))
agent_kruger 25-Dec-13 4:27am    
please give us the structure of your Place Table.

1 solution

Quote:
Invalid Column Name
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900