473,508 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert the textbox value to database and retrive it to List Box

30 New Member
hi evryone..
i want to get the text box value to list box .
And also i want this textbox value enter into the dabasex table called Area and @ th esame time insert this value to List box. here is the code wich i have use.


Expand|Select|Wrap|Line Numbers
  1. SqlConnection conn = new SqlConnection(ConnectionString);
  2.                 String S = "Insert into Area values ('" + textBox1.Text.ToString().Trim() + "')";
  3.                 SqlCommand command = new SqlCommand(S);
  4.                 SqlDataAdapter da = new SqlDataAdapter(S,ConnectionString);
  5.               // DataSet dt = new DataSet();
  6.                 DataTable dt = new DataTable();
  7.                 da.Fill(dt);
  8.  
  9.                textBox1.Clear();
  10.                 listBox1.Items.Add(dt.Rows[0].ItemArray[0].ToString());
  11.  
but here DataTable is not filling. Can any1 tell me what is the problem here.
thank you everyone.
Jan 11 '10 #1
3 3767
ThatThatGuy
449 Recognized Expert Contributor
Aren't you getting an error....

you are trying to fill a datatable by passing an insert query instead of a select query....

insert queries don't fetch values its select queries
Jan 11 '10 #2
mzmishra
390 Recognized Expert Contributor
Why you want to use datatable to insert textbox value to the listbox.
Jan 14 '10 #3
buterfly0707
30 New Member
i figured this out. thanks for all.

ThatThatGuy: thanks.
mzmishra : thanks for reply. yah no need of datatable here.
Jan 18 '10 #4

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

Similar topics

3
4483
by: Nicolae Fieraru | last post by:
Hi All, I have a problem and I can't figure out how to solve it. My database has three tables: tblCustomers, with CustomerId and CustomerName tblProducts, with ProductId and ProductCode...
3
2258
by: Sagi | last post by:
if i use the insert to add a new row to the access database, something like: INSERT INTO tblCat (CatName,CatOrder,StoreID) VALUES( '" & strNewCat&"', "& strMaxiO& ", 1); and there is another...
1
2912
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
10
11164
by: Ricardo | last post by:
How can I make a insert sql string to insert direct in a table(not a dataset) using the textbox.text propert??
0
1177
by: Tim::.. | last post by:
Can someone please help! I'm trying to write an insert statement for a complex datagrid! The database consists of the following data structure! ..tblContent PageID PK ModDate Description...
13
2429
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
4
2006
by: PerumalSamy | last post by:
Hi, i am doing program in asp.net using vb coding and MS Access as back end. i am having a table with date field and manipulation is based on the same. i am inserting value from textbox...
2
5847
by: blitzztriger | last post by:
Hello!! how do i insert values into mysql , after parsing a submiting textbox?? I made the arrays, so this should be a basic insertion of them in the db, but something is missing, or in the wrong...
1
1623
by: ganesh22 | last post by:
Hi, Here the below code is for dynamically creating textboxs, its creating fine but after user enters some values in textboxs how can i retrive that values? using System; using System.Data;...
0
7132
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...
0
7401
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...
1
7063
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...
0
7504
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
5640
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,...
0
3211
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...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
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 ...
0
432
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...

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.