473,769 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

selecting one row from datagrid

I want to select one Row from a datagrid so I create a
textBbox(txtnam e) and Button for the user to write the name in textBox
and By the click of the button it select the corresponding row. But
it's not selecting the row neighther I'm getting any mistake message
I'm I missng some thing? I wrote the code on Button_Click sqlCommand as
follows:
SqlCommand myCommand = new SqlCommand("SEL ECT * from employee where
fullname Like %+txtname+%" ,con);
Thank you.

Jan 10 '07 #1
4 1379
Well, I'm not quite sure if you made mistake when you wrote this post, but,
according to
what you wrote here, mistake is in string concatenation. You should write:
SqlCommand myCommand = new SqlCommand("SEL ECT * from employee where
fullname Like %" + txtname + "%" ,con); // Note opening and closing quotes

Furthermore, if txtname is id of textbox (and not the string) then you
should write txtname.Text
This much I could write, because you haven't supplied much info...

"rcoco" <nc******@yahoo .cawrote in message
news:11******** **************@ 77g2000hsv.goog legroups.com...
>I want to select one Row from a datagrid so I create a
textBbox(txtnam e) and Button for the user to write the name in textBox
and By the click of the button it select the corresponding row. But
it's not selecting the row neighther I'm getting any mistake message
I'm I missng some thing? I wrote the code on Button_Click sqlCommand as
follows:
SqlCommand myCommand = new SqlCommand("SEL ECT * from employee where
fullname Like %+txtname+%" ,con);
Thank you.

Jan 10 '07 #2
Thanks,
the whole code actually goes like this as per now hope you could hlp
me:

try
{
con.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="SELECT * from employee where fullname Like
%"+@txtname.Tex t+"%";
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds,"isp_email.s taff");
con.Open();
myCommand.Execu teNonQuery();
dgupdate.DataSo urce=ds;
dgupdate.DataBi nd();
con.Close();
}
catch(Exception err)
{
Console.WriteLi ne(err.Message) ;
}
finally
{
con.Close();
}
Thank you

Jan 10 '07 #3
bpd
I believe you just need to remove the @ in front of txtname.text.

rcoco wrote:
Thanks,
the whole code actually goes like this as per now hope you could hlp
me:

try
{
con.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="SELECT * from employee where fullname Like
%"+@txtname.Tex t+"%";
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds,"isp_email.s taff");
con.Open();
myCommand.Execu teNonQuery();
dgupdate.DataSo urce=ds;
dgupdate.DataBi nd();
con.Close();
}
catch(Exception err)
{
Console.WriteLi ne(err.Message) ;
}
finally
{
con.Close();
}
Thank you
Jan 10 '07 #4
Well, as bpd said, first you should remove @.
Then, after line: "myAdapter.Fill ..." ...
there is no need to perform opening con, executing command and closing con
again,
(unless you are trying to do something else with that?)
adapter should do it for you, but there is nothing wrong if you are opening
and closing manually.

So, your try block should be something like this...
try
{
con.Open(); // Assuming that con object is properly created with correct
connection string
SqlCommand myCommand = new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="SELECT * from employee where fullname Like %" +
txtname.Text + "%";
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds,"isp_email.s taff");
con.Close();
dgupdate.DataSo urce=ds;
dgupdate.DataBi nd();
}

"bpd" <br*********@ro llcoater.comwro te in message
news:11******** **************@ i56g2000hsf.goo glegroups.com.. .
>I believe you just need to remove the @ in front of txtname.text.

rcoco wrote:
>Thanks,
the whole code actually goes like this as per now hope you could hlp
me:

try
{
con.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Conn ection=con;
myCommand.Comm andText="SELECT * from employee where fullname Like
%"+@txtname.Te xt+"%";
SqlDataAdapt er myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill (ds,"isp_email. staff");
con.Open();
myCommand.Exec uteNonQuery();
dgupdate.DataS ource=ds;
dgupdate.DataB ind();
con.Close();
}
catch(Exceptio n err)
{
Console.WriteL ine(err.Message );
}
finally
{
con.Close();
}
Thank you

Jan 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1416
by: alexB | last post by:
Could it be that the data has changed in such a way as to produce the unexpected results? Or could a newer/older version of the .net framework have been installed on the server? >-----Original Message----- >All, > I have a datagrid and populate the grid from a table. I >also have a bound column to select the row for me to
2
1343
by: Sam74 | last post by:
Hi, I'm writing a program with Microsoft Visual C# .net version 2002 the program has 4 Forms and all the database components (DataSet, OleDbDataAdapter, OleDbConnection) are in form4 as I've got DataGrids in the other forms, if I go in one of these forms in the datagrid property, selecting the DataSource I can't select the dataset in form4 how can I see the dataset in form4 from the other forms? thankyou
2
1347
by: Michael Cairns | last post by:
Im trying to work out how to select a row and change the appearance of the selected row i a datagrid. I might also try to show the details of a selected row on a panel in the page. Is this difficult to do?? Could someone point me in the right direction for the this
6
13584
by: aaa | last post by:
Hi I am trying to create a read-only DataGrid that would always have current row selected. Currently, I am using method: public void SelectDataGridRow(DataGrid dg) { if (dg.CurrentRowIndex > -1) { dg.Select(dg.CurrentRowIndex);
1
1886
by: orekinbck | last post by:
Hi There I have a datagrid whose main purpose in life is to provide a nice way for users to make a single choice from a list. The grid is read only, single row select and has its data source as an ArrayList. I came up against the issue of selecting a cell and getting the whole row to highlight, and the second issue of unhighlighting any previously selected row. To get around these two issues I have put in a two prong approach:
6
2057
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I need to use parts of the tables in datagrids, and here is where my problem lies
1
2242
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that caused me other problems. Any ideas? Thanks, Jay
1
3354
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been able to find any examples which demonstrate how to do this. My Code:
2
7500
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView nodes. The TreeView populates dynamically as there are a significant number of nodes. The DataGrid displays both the items and the nodes from the TreeView. Using the explorer analogy this means the TreeView shows folders, and the DataGrid folders...
0
1187
by: Satiz | last post by:
Hi All, I've a TreeView(IE Webcontrol) and a DataGrid in my VS.Net 2003 ASP.Net web form. My problem : If i select a particular node(it may be parent, child or leaf), then the corresponding values from a dataTable should be displayed in the DataGrid. I've a code-behind function for LoadGrid(), this is calling selecting a node and clicking a button only, I want to load grid while selecting a node. Pls give me the codes and ideas to do, it's...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.