473,396 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

retreive values from the database in asp.net using c#

35
hello,

I have written below code for retreiving the values from database into the textboxes only when I enter id into the textbox.
but it doesn't show any values ino the textboxes.

please tell how it will be done.

da = new SqlDataAdapter("select * from customers where customerid=" + '" + txtcustid.Text + "' ,conn);

DataSet ds = new DataSet();
da.Fill(ds,"customers");

for(s=0;s<ds.Tables[0].Rows.Count ;s++)
{
if( txtcustid.Text== ds.Tables[0].Rows[s]["customerid"].ToString() )
{
txtcustid.Text =ds.Tables[0].Rows[s] ["customerid"].ToString();

Txtcustname .Text =ds.Tables[0].Rows[s]["contactname"].ToString();
Txtdept.Text= ds.Tables[0].Rows[s]["organisation"].ToString();
}
break;
}
Jan 8 '07 #1
3 7619
hello,

I have written below code for retreiving the values from database into the textboxes only when I enter id into the textbox.
but it doesn't show any values ino the textboxes.

please tell how it will be done.

da = new SqlDataAdapter("select * from customers where customerid=" + '" + txtcustid.Text + "' ,conn);

DataSet ds = new DataSet();
da.Fill(ds,"customers");

for(s=0;s<ds.Tables[0].Rows.Count ;s++)
{
if( txtcustid.Text== ds.Tables[0].Rows[s]["customerid"].ToString() )
{
txtcustid.Text =ds.Tables[0].Rows[s] ["customerid"].ToString();

Txtcustname .Text =ds.Tables[0].Rows[s]["contactname"].ToString();
Txtdept.Text= ds.Tables[0].Rows[s]["organisation"].ToString();
}
break;
}
Hi...
i think u may have some pblm while u specify d sqlquery
ie. while calling d SqlDataAdapter() constructor by passing d query...
try like dis...

da = new SqlDataAdapter("select * from customers where
customerid ='"+ txtcustid.Text + "'" ,conn);

hope this helps...
thanx and rgrds..
sand...
Jan 8 '07 #2
Hi,
Here is the modified code.

DataSet ds =new DataSet();
SqlDataAdapter da= new SqlDataAdapter("select * from Customers","database=Test;server=Test;uid=test;pwd =test");
da.Fill(ds);
for(i=0;i<ds.Tables[0].Rows.Count;i++) ///or if(ds.Tables[0].Rows.Count>0)
{
TextBox1.Text= ds.Tables[0].Rows[0]["CustomerID"].ToString();
TextBox2.Text=ds.Tables[0].Rows[0]["CustomerName"].ToString();
TextBox3.Text=.................................... .
}

I had tested it and its working well.
Hope It will help you.

Vivek Rathore.

hello,

I have written below code for retreiving the values from database into the textboxes only when I enter id into the textbox.
but it doesn't show any values ino the textboxes.

please tell how it will be done.

da = new SqlDataAdapter("select * from customers where customerid=" + '" + txtcustid.Text + "' ,conn);

DataSet ds = new DataSet();
da.Fill(ds,"customers");

for(s=0;s<ds.Tables[0].Rows.Count ;s++)
{
if( txtcustid.Text== ds.Tables[0].Rows[s]["customerid"].ToString() )
{
txtcustid.Text =ds.Tables[0].Rows[s] ["customerid"].ToString();

Txtcustname .Text =ds.Tables[0].Rows[s]["contactname"].ToString();
Txtdept.Text= ds.Tables[0].Rows[s]["organisation"].ToString();
}
break;
}
Jan 8 '07 #3
aaryan
82
hello,

I have written below code for retreiving the values from database into the textboxes only when I enter id into the textbox.
but it doesn't show any values ino the textboxes.

please tell how it will be done.

da = new SqlDataAdapter("select * from customers where customerid=" + '" + txtcustid.Text + "' ,conn);

DataSet ds = new DataSet();
da.Fill(ds,"customers");

for(s=0;s<ds.Tables[0].Rows.Count ;s++)
{
if( txtcustid.Text== ds.Tables[0].Rows[s]["customerid"].ToString() )
{
txtcustid.Text =ds.Tables[0].Rows[s] ["customerid"].ToString();

Txtcustname .Text =ds.Tables[0].Rows[s]["contactname"].ToString();
Txtdept.Text= ds.Tables[0].Rows[s]["organisation"].ToString();
}
break;
}
hi muskan,
i remember reading it somewhere that if we want to filter a query this is the bad way of doing it
[HTML]da = new SqlDataAdapter("select * from customers where customerid=" + '" + txtcustid.Text + "' ,conn); [/HTML]
to know much about it, you can go thro the following link. hope it will help you.
http://www.csharp-station.com/Tutori.../Lesson06.aspx
Jan 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Pato Secruza | last post by:
Hi everyone! I have a really frustrating error and need help. I’m trying to do a function that gets the properties and names of the fields in a MS Access database using ASP. I haven’t...
9
by: Peter | last post by:
Hello£¬everyone, My program will collect a testing machine's data ,save the data and deal with the data everyday. I want to use vb.net to create database, add and delete tables or modify the...
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
0
by: wingtong | last post by:
Our Deltek accounting software will be migrating from a Jet database to a SQL express database. In the past, when using the Jet database, I have been able to make a copy of the JET database to my...
2
by: Justin Fancy | last post by:
Hi everyone, I need some help. I'm placing text files into a created database using vb.Net. The problem is that, i need two seperate sql statements to add both files because they are in...
0
by: tarkuser | last post by:
Hai... I have problem in storing values from flash to database and to select data from a database using Javascript. First i get details of a student through flash and then sotre it to database...
6
by: ndeeley | last post by:
Hi, How do I insert a null or blank field into a database using coldfusion? I'm new to CF and its proviing a bit tricky! My database date field accepts null values (I think - theres no default...
0
by: kino | last post by:
I am trying to test storing images in a database, I got this code after searching on Google but it doesn't work: protected void Button1_Click(object sender, EventArgs e) { string...
1
by: santhanalakshmi | last post by:
Hi, I wrote some coding, to import excel data in mysql database using PHP Script? But my script, its not all inserting the excel data in mysql database. I don't know, what mistake did i made?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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...
0
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,...

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.