473,738 Members | 7,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Something Wrong?

Hi,
I'm just wondering if I'm on the write truck. this code is ment to look
for an ID number in the datagrid that matches the the ID number that is
in the textbox I created.
But it's not selecting neither is it showing me any error. could some
one help me please?

private void bttok_click(obj ect sender, System.EventArg s e)
{
SqlCommand myCommand = new SqlCommand("sel ect * from employee where
txtname.text=id ",con);
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds);
con.Open();
myCommand.Execu teNonQuery();
datagrid1.DataS ource=ds;
datagrid1.DataB ind();
con.Close();
}
Thanks.

Jan 9 '07 #1
9 1291
Hi,

First, your sql command does not seem right. Assuming you have a column
called 'txtname.text' you should use an SqlParameter for the value.

DataAdapter.Fil l will open the connection and close it afterwards by
itself unless the connection is already open.

myCommand.Execu teNonQuery(); serves no function as you aren't using the
result for anything.

This may also be a good time to learn about the 'using' statement, so your
method can be rewritten to the following (beware of linewraps)

private void bttok_click(obj ect sender, System.EventArg s e)
{
// assuming there is a string variable called id and a
connection string called conString
using (SqlConnection con = new SqlConnection(c onString))
{
using (SqlCommand myCommand = new SqlCommand("sel ect *
from employee where txtname.text=@i d", con))
{
SqlParameter myParameter = new SqlParameter("@ id",
SqlDbType.Text) ;
myParameter.Val ue = id;
myCommand.Param eters.Add(myPar ameter);

using (SqlDataAdapter myAdapter = new
SqlDataAdapter( myCommand))
{
DataSet ds = new DataSet();
myAdapter.Fill( ds);

datagrid1.DataS ource = ds;
datagrid1.DataB ind();
}
}
}
}

You may also want to catch any exception thrown if the query or connection
fails in any way to figure out what is wrong.


On Tue, 09 Jan 2007 08:01:47 +0100, rcoco <nc******@yahoo .cawrote:
Hi,
I'm just wondering if I'm on the write truck. this code is ment to look
for an ID number in the datagrid that matches the the ID number that is
in the textbox I created.
But it's not selecting neither is it showing me any error. could some
one help me please?

private void bttok_click(obj ect sender, System.EventArg s e)
{
SqlCommand myCommand = new SqlCommand("sel ect * from employee where
txtname.text=id ",con);
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds);
con.Open();
myCommand.Execu teNonQuery();
datagrid1.DataS ource=ds;
datagrid1.DataB ind();
con.Close();
}
Thanks.


--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 9 '07 #2
Thank you very much but it's not showing any changes even after trying
the try&cacth.

Jan 9 '07 #3
I'm not entirely sure I understand your problem. Is your query not
returning anything? (Set a breakpoint after DataAdapter.Fil l to see if it
the DataSet contains any data). Can you query the database directly using
Query Analyzer or Sql Server Management Studio?

If the button event runs without any exceptions, the query is well formed,
and the connection valid, but the query itself may not be asking what you
think it does.
On Tue, 09 Jan 2007 09:46:09 +0100, rcoco <nc******@yahoo .cawrote:
Thank you very much but it's not showing any changes even after trying
the try&cacth.


--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 9 '07 #4
Looking at your SQL Command I would assume that txtname.text is not a
column name, but refers to a textbox on your form.
If that is the case, changing your sqlcommand like this might help:
SqlCommand myCommand = new SqlCommand("sel ect * from employee where id
= " + txtname.Text,co n);

Sincerely,
Kevin Wienhold

rcoco schrieb:
Hi,
I'm just wondering if I'm on the write truck. this code is ment to look
for an ID number in the datagrid that matches the the ID number that is
in the textbox I created.
But it's not selecting neither is it showing me any error. could some
one help me please?

private void bttok_click(obj ect sender, System.EventArg s e)
{
SqlCommand myCommand = new SqlCommand("sel ect * from employee where
txtname.text=id ",con);
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds);
con.Open();
myCommand.Execu teNonQuery();
datagrid1.DataS ource=ds;
datagrid1.DataB ind();
con.Close();
}
Thanks.
Jan 9 '07 #5

Actually The Problem is that When I put An Id number in the text Box
and I press the Button There is no row selected yet I want it to select
the row.

Jan 9 '07 #6
On Tue, 09 Jan 2007 09:46:09 +0100, rcoco <nc******@yahoo .cawrote:
>
>Thank you very much but it's not showing any changes even after trying
the try&cacth.

--Happy Coding!
Morten Wennevik [C# MVP]
Did you implemented catch part of code
- - - - - - - - - - - - - - - - - - - -
try
{
// some code
}
catch(Exception ex)
{
}
- - - - - - - - - - - - - - - - - - - -
is not enough.
You have to do something with your exception, for example
- - - - - - - - - - - - - - - - - - - -
try
{
// some code
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
//or
//MessageBox.Show (ex.Message);
//or
//Form1.label1.te xt= "Error, unable to load data, see details below. \n"
+ ex.Message;
}
- - - - - - - - - - - - - - - - - - - -
best,
Slawomir
Jan 9 '07 #7

Thanks Guys I seem not to get exactly what is wrong with this work
because it's like every thing I try it's not working Let me keep trying
if i get it I will tell you.
Thanks again.

Jan 9 '07 #8
thanks,
But i still don't see where I'm going wrong it's not changed . thanks
any way for the help.

Jan 9 '07 #9
You still haven't told us any specifics around your problem. Do you get
an exception? Does the query work in the database?
On Tue, 09 Jan 2007 13:36:48 +0100, rcoco <nc******@yahoo .cawrote:
thanks,
But i still don't see where I'm going wrong it's not changed . thanks
any way for the help.


--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 10 '07 #10

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

Similar topics

14
2150
by: Luka Milkovic | last post by:
Hello, I have a little problem and although it's little it's extremely difficult for me to describe it, but I'll try. I have written a program which extracts certain portions of my received e-mail. The content of the e-mail is actually predictable, it has one very long list of numbers, something looking like this:
0
1585
by: Steve | last post by:
Hi, Is there something fundamentally wrong with the following query? SELECT MAX(OrderID) AS Expr1 FROM Orders WHERE (MarketActionCode = 'S') AND (OrderLegCode = 'S') AND (Status = 'F') AND (AttemptID IN (SELECT AttemptID FROM ATTEMPT WHERE EventID = ?)) I pass in the EventID (in this case 1). the query returns the correct OrderID when I test it in sql2000 but for some reason fails to return a value when I use Java code. There is...
5
2340
by: uberderf | last post by:
I have the following web page setup: http://angels.uberderf.com/glossary.html I have a 2 column table layout which is a glossary of terms and their meanings. When you view this page in firefox the first row displays with a lot of space below the two cells. The rest of the table looks as it was intended to look. This same page viewed in Mozilla looks correct or how it was intended to look. Even IE displays the page as intended.
6
1598
by: Vandana Rola | last post by:
Hello Everyone, I posted this question earlier under creating Multiple choice quiz. Is it possible to ignore something using javascript. What I am trying to do is creating a multiple answer quiz. I have five choices out of which user are supposed to choose 3 best choices. The user should get feedback on the choices they make. I have been able to provide the feedback for all the choices but my problem is I am also getting the feedback on...
6
6580
by: Michael Sparks | last post by:
Hi, I suspect this is a bug with AMK's Crypto package from http://www.amk.ca/python/code/crypto , but want to check to see if I'm being dumb before posting a bug report. I'm looking at using this library and to familiarise myself writing small tests with each of the ciphers. When I hit Crypto.Cipher.ARC4 I've
11
2351
by: matsi.inc | last post by:
I am looking to make something like a delegate that i can use in my projects but am having a hard time getting started. The behavior I am most interested in is how a delegate changes it's Invoke method dynamically to match the arguments supplied to it when it is defined. For example... public delegate void MyDelegate(string myString, int myInt);
5
2914
by: Simon Brooke | last post by:
This is supposed to be a very simple XSL stylesheet to strip styling information out of HTML documents - it could not be more basic. And yet, it doesn't work. I'm obviously getting something very basic wrong and for the life of me I can't see it. Please, somebody, cast your eyes over this and tell me what's wrong! First, the XSL stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"
25
3123
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of course then the file doesn't get seen by the user. Is there any command that essentially executes the code and then echo's it? something that will take a string like '<body>blah<?php echo 'Hello'; ?></body>' and actually interpret the php
3
1883
by: Peter Oliphant | last post by:
It's not necessary, but it would be nice if there was a way I could easily create something like a 'web browser form' or a 'display web page form' as forms in my application (in a Panel would be even better!). Something that allows browsing the internet within the window, or possibly just display a web page that I choose (as the application author in code) to show without the ability to browse. The later ability would allow me to change,...
34
1802
by: raphfrk | last post by:
This program should copy one file onto the other. It works if I compile it with gcc to a cygwin program. However, if I compile it with the -mno-cygwin option, it doesn't work (this targets native windows). Anyway, I just want to check that the program is valid before I see if I can find a way around a compiler bug. It might be something simple that I am doing wrong.
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9476
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...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
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
8210
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
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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
3
2193
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.