Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 13th, 2006, 07:19 PM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using textbox, button control to search database

I am beginning at C#. I am trying to write an application that connects, searches our database via ADO.NET and bind the values to textbox controls.

Sample Program: Enter customer ID in textbox1, click search button, and display values in textboxes. Problem that I am having is creating the entry point textbox code. Here is the code I have so far.

private void button3_Click(object sender, EventArgs e)
        {


string select = "select * from customer where master_customer_id=" + textBox3.Text;
string source = @"Data Source=DB;database=TTST;User id=sa;Password=;";
SqlConnection conn = new SqlConnection(source);
conn.Open();
//Use SqlDataAdapter to fill rows to dataset
SqlDataAdapter da = new SqlDataAdapter(select, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Customer");

//Binding Data to Textbox Control
textBox1.DataBindings.Add("Text", ds, "customer.first_name");
textBox2.DataBindings.Add("Text", ds, "customer.last_name");

        }

I get the following error when I try to run and Enter in textbox3 - 000000000001, Click search
error:
Arithmetic overflow error converting numeric to data type numeric

 
Old May 13th, 2006, 08:31 PM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

from the first look,
string select = "select * from customer where [u]master_customer_id=" + textBox3.Text</u>;
the place where u are using textbox3.text ; // first line of your submitted code.
it should be something like Convert.ToInt32(textbox3.text); // this is based on assumption that id (master_customer_id) is int or long (numeric rather than alpha numeric).

 
Old May 15th, 2006, 03:14 AM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This worked out. Thank you for your help on this.

One more question, how or where can I implement the e.g. data adapter da, or dataset ds clear() command if I wanted to run search for another ID?


 
Old May 17th, 2006, 05:25 PM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I didnt get your question ! Can u be more specific.
by the way i found this cool presentation on ADO .Net
have a look if this helps or reframe your question :)
http://www.bits-pilani.ac.in:12360/c.../Lecture19.ppt

 
Old May 17th, 2006, 06:54 PM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.

Refer to topic: Text

For more clarification. I figured out a solution for it already.
I have all the books I need in front of me. I look to forums for other programmers expertise and techniques :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Search button doesn't search Access DB cbones Visual Studio 2008 1 October 27th, 2008 07:36 PM
search on the basics of textbox value Kanhaiyasharma ADO.NET 0 April 23rd, 2007 11:38 PM
search button ct Excel VBA 0 April 11th, 2006 09:50 AM
Enable button when textbox is populated Freddyfred Access VBA 2 April 19th, 2004 09:02 PM
How to search and display in textbox a specific .. arshad mahmood VB Databases Basics 1 July 11th, 2003 08:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.