473,395 Members | 1,745 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,395 software developers and data experts.

updating database from textbox

hi
I am trying to update the table records by intering a new values in a textbox
and am facing problems in the code of dataset
how could I perform that
thanx
Attached Files
File Type: txt New Text Document (4).txt (1.2 KB, 474 views)
Apr 5 '10 #1
3 2472
Frinavale
9,735 Expert Mod 8TB
I can't open the file you attached.
You should post any code that you are having problems with in the thread (because apparently some people can't open the files attached). When you post code please post it within code tags.

Anyways, you need a TextBox on the page. Then you need to access the Text in the TextBox (using the TextBox.Text property). Once you've got that you should use it to update your database.

The best way to supply this value (that has been provided by the end user) is to use the SqlCommand.Parameters property (if you're using the SqlCommand object).


This topic is covered nicely in:
How to use database in your program Part 1
How to use database in your program Part 2

-Frinny
Apr 6 '10 #2
CroCrew
564 Expert 512MB
This is what I got from abdulhadi's attached file:

Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         SqlConnection conn;
  4.         conn = new SqlConnection();
  5.         conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\matches.mdf;Integrated Security=True;User Instance=True";
  6.  
  7.         conn.Open();
  8.  
  9.         SqlCommand selectcmd;
  10.         selectcmd = new SqlCommand();
  11.         selectcmd.Connection = conn;
  12.         string selecting;
  13.         selecting = "select * from statistics where club=@club";
  14.         selectcmd.Parameters.Add("club", TextBox1.Text);
  15.         selectcmd.CommandText=selecting;
  16.  
  17.  
  18.         SqlCommand upcmd;
  19.         upcmd = new SqlCommand();
  20.         upcmd.Connection = conn;
  21.         string adcmd;
  22.         adcmd = "Update statistics Set goals=goals+2,points=points+3,win=win+1)";
  23.         upcmd.CommandText = adcmd;
  24.  
  25.         SqlDataAdapter da;
  26.         da = new SqlDataAdapter();
  27.         da.SelectCommand = selectcmd;
  28.  
  29.  
  30.         DataSet newrecord;
  31.         newrecord = new DataSet();
  32.         da.Fill(newrecord);
  33.         da.UpdateCommand = upcmd;
  34.         da.Update(newrecord);
  35.         GridView1.DataSource = newrecord;
  36.         GridView1.DataBind();
  37.  
CroCrew~
Apr 6 '10 #3
Frinavale
9,735 Expert Mod 8TB
Ahh, it's line 14 that's causing the problem :)
You need to look at how to use the SqlParameterCollection.Add method.


It should be something like:
Expand|Select|Wrap|Line Numbers
  1. sqlCom.Parameters.Add("@club",  SqlDbType.VarChar).Value =  TextBox1.Text;
Apr 6 '10 #4

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

Similar topics

0
by: cwbp17 | last post by:
Have two tables that have a FK relationship on ID column. Have one datagrid that displays all of the columns of both tables. What's the best approach on updating a row from the datagrid back to...
1
by: sandman | last post by:
I've got a simple windows form with some bound textboxes and Save button. Each texbox is bound to column in a table in an Access database. The form fills fine - all the fields show the correct...
3
by: Jon Agiato | last post by:
Hi, I am trying to use a data grid in a web application in which I have three tiers. The DataGrid is not set up to a data source, or a data adapter, so everytime I make a change I send the cell...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
0
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
3
by: Spoogledrummer | last post by:
Hi it's me again, still working on the sam 5 minute problem so feeling kind of thick now. I've dumped the idea of using a textarea for now and am using a textbox instead but am struggling when it...
23
by: tanya2001 | last post by:
hi all.. I am trying to update my datagrid in my webform...but its not getting updated..though in the database it removing the <null> and inserting a blank field....its not taking the input which m...
2
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
0
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't...
1
by: cerilocke | last post by:
I have a repeater in which I have a hidden field (input type = hidden), a textbox (asp:TextBox), a checkbox (input type = checkbox) and a label (asp:Label). I have bound all four items to the same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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
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...

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.