Hai All,
Please help me on this
How to Update the Data which is present in the textboxes, the data is retrived from the database to textboxes, Just i want to modify and to update in the Database i am trying this in C# language please help me out
Thank u
7 1818
I tried by using following Code but its taking only direct values but its not updating whatever the content Present in textboxes.. plz tell me how to Update the content of textbox
string sql = "Update UserGroups SET grpDescription= @grpDescription , grpActive=@grpA ctive, grpToDate=@grpT oDate where(grpID =@grpID)";
SqlCommand cm = new SqlCommand(sql, myConnection);
//cm.CommandText = sql;
//cm.Connection = myConnection;
cm.Parameters.A dd(new SqlParameter("@ grpID", SqlDbType.Int, 255));
cm.Parameters["@grpID"].Value ='3';
//cm.Parameters.A dd("@grpID", SqlDbType.Int, 255).Value =Request.QueryS tring["id"];
cm.Parameters.A dd(new SqlParameter("@ grpDescription" , SqlDbType.VarCh ar, 50));
cm.Parameters["@grpDescriptio n"].Value =txtGrpDescript ion.Text;
cm.Parameters.A dd(new SqlParameter("@ grpActive", SqlDbType.VarCh ar, 50));
cm.Parameters["@grpActive "].Value = rdbValid.Select edItem.Text;
// cm.Parameters.A dd("@grpFrmDate ", SqlDbType.DateT ime).Value = txtFrmDate.Text ;
cm.Parameters.A dd(new SqlParameter("@ grpToDate", SqlDbType.DateT ime));
cm.Parameters["@grpToDate "].Value = txtToDate.Text;
//I THINK I AM LOSSING HERE
try
{
myConnection.Op en();
//myConnection.Op en();
cm.ExecuteNonQu ery();
myConnection.Cl ose();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
I tried by using following Code but its taking only direct values but its not updating whatever the content Present in textboxes.. plz tell me how to Update the content of textbox
string sql = "Update UserGroups SET grpDescription= @grpDescription , grpActive=@grpA ctive, grpToDate=@grpT oDate where(grpID =@grpID)";
SqlCommand cm = new SqlCommand(sql, myConnection);
//cm.CommandText = sql;
//cm.Connection = myConnection;
cm.Parameters.A dd(new SqlParameter("@ grpID", SqlDbType.Int, 255));
cm.Parameters["@grpID"].Value ='3';
//cm.Parameters.A dd("@grpID", SqlDbType.Int, 255).Value =Request.QueryS tring["id"];
cm.Parameters.A dd(new SqlParameter("@ grpDescription" , SqlDbType.VarCh ar, 50));
cm.Parameters["@grpDescriptio n"].Value =txtGrpDescript ion.Text;
cm.Parameters.A dd(new SqlParameter("@ grpActive", SqlDbType.VarCh ar, 50));
cm.Parameters["@grpActive "].Value = rdbValid.Select edItem.Text;
// cm.Parameters.A dd("@grpFrmDate ", SqlDbType.DateT ime).Value = txtFrmDate.Text ;
cm.Parameters.A dd(new SqlParameter("@ grpToDate", SqlDbType.DateT ime));
cm.Parameters["@grpToDate "].Value = txtToDate.Text;
//I THINK I AM LOSSING HERE
try
{
myConnection.Op en();
//myConnection.Op en();
cm.ExecuteNonQu ery();
myConnection.Cl ose();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
What is the exact error you are receving?
I tried by using following Code but its taking only direct values but its not updating whatever the content Present in textboxes.. plz tell me how to Update the content of textbox
string sql = "Update UserGroups SET grpDescription= @grpDescription , grpActive=@grpA ctive, grpToDate=@grpT oDate where(grpID =@grpID)";
SqlCommand cm = new SqlCommand(sql, myConnection);
//cm.CommandText = sql;
//cm.Connection = myConnection;
cm.Parameters.A dd(new SqlParameter("@ grpID", SqlDbType.Int, 255));
cm.Parameters["@grpID"].Value ='3';
//cm.Parameters.A dd("@grpID", SqlDbType.Int, 255).Value =Request.QueryS tring["id"];
cm.Parameters.A dd(new SqlParameter("@ grpDescription" , SqlDbType.VarCh ar, 50));
cm.Parameters["@grpDescriptio n"].Value =txtGrpDescript ion.Text;
cm.Parameters.A dd(new SqlParameter("@ grpActive", SqlDbType.VarCh ar, 50));
cm.Parameters["@grpActive "].Value = rdbValid.Select edItem.Text;
// cm.Parameters.A dd("@grpFrmDate ", SqlDbType.DateT ime).Value = txtFrmDate.Text ;
cm.Parameters.A dd(new SqlParameter("@ grpToDate", SqlDbType.DateT ime));
cm.Parameters["@grpToDate "].Value = txtToDate.Text;
//I THINK I AM LOSSING HERE
try
{
myConnection.Op en();
//myConnection.Op en();
cm.ExecuteNonQu ery();
myConnection.Cl ose();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
Hi Nanditha,
Ur problem is simple,The code u have used is absolutely correct, no problem in that, the problem is ur binding the values in textboxes from Database, Ur doing this in PageLoad event right?
When u change the values in textboxes and click Save button the page gets PostBack and again the values in Database is binded in textboxes, ur updated values are lost.
To avoid this,In the Pageload, put the whole code which gets the values from Database inside the
just do this in PageLoad - if(!IsPostBack)
-
{
-
//ur code to get values from databse
-
}
this will prevent the values from DB binding to textbox each time u click save.
Hope u can proceed with this
If ur not clear feel free to ask me.
Thanks
Saravanan.
What is the exact error you are receving?
I am not getting any error but the data is not updated thats all
I am not getting any error but the data is not updated thats all
I think ur not getting me right,
U wont get any error, but when u Click the save button, the values u changed will be losed,and values from the database will be got again and the textboxes will hold this old value, this old value will be updated in the Database,
See the below code for reference.
I will bet money, this will work. - protected void Page_Load(object sender, EventArgs e)
-
{
-
if (!IsPostBack)
-
{
-
//Ur code to get values from Database
-
}
-
-
}
-
}
No NO.. I got it.. its working now.. ya i was doing same mistake what u told
Once again Thank u..
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 data for the record I load. So
then I change the contents of one of the textboxes and
click on the Save button. The button's event handler then
calls the data adapter's Update method and I check the
return value. Nada-zilch-nothing. I even put a...
|
by: Jon S via DotNetMonster.com |
last post by:
Hi all
I'm new to C# and ADO.Net. I've managed to insert, update and delete records
from a database but I need to know how to show these changes immediately.
For example : If I delete a record from the database, that deleted record
will remain in my forms textboxes until I restart the program. Is there a
way to remove that record straight away after deleting it from the database??
I expect it is something very simple but I'm not...
|
by: OldStd |
last post by:
Updating data using 2 data sets
I am having some problems in updating the database using two datasets as suggested by someone.
1. Data is displayed in a data grid from a dataset generated using the IDE that pulls data from two tables using an . The idea is to display the associated with the field. Because an is used, the IDE couldn’t auto-generate the Insert command, update command, or Delete command.
2. As a result, it was suggested...
|
by: Wavey |
last post by:
Hi All,
I have a problem with updating an Access database from a datatable. I have two rows of data in my database at the moment for testing, the first row is an ID number (primary key), the second is a name and the third is a price.
I can get this data out of the database, store it in a datatable in a dataset and display the name in a listbox with the name and price displayed in textboxes.
If I change the data for the second row data...
|
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...
| |
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |