Click here to Skip to main content
12,759,698 members (34,175 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
Data base Structure as follows in Ms Access;

Name Text
Day Text

Design as follows;

Name Combo box
Day Combo box

In the name column,all names retrieved from the database and display into the Combo box.
In the day column day from sunday to saturday is maually by coding.

in the run mode. when i select the Name and Day and click the save button. the records are saved in the database.

in the database records as follows

Suresh Sunday
Suresh Monday

i have one search button, when i click the search button, the above two records are displayed in the datagridview.

In the datagridview records as follows;

Name Day
Suresh Sunday
Suresh Monday

when i click the first record suresh in datagridview the particular record is display in to the combobox.

in that suppose i want to update the first record (suresh) sunday changed in to friday and click the update the database for suresh all entries day is updated into friday. but i want to update the friday for the first reocord only.

output as follows;

Suresh Friday
Suresh Friday

But i want the ouput as follows after click the update butotn

Suresh Friday
Suresh Monday

how to update.for that how can i do using csharp.

please help me.

Regards & Thanks,
Narasiman P.
Posted 18-Feb-13 19:36pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Check your WHERE Clause in update Statement; condition should not be given by name. Instead use a Primary key in WHERE CLAUSE.
Member 8054539 19-Feb-13 1:39am
can i use name as primary key.suppose i set primary key as name,

the below entries is possible.

Suresh Monday
Suresh Friday

please help me.

thanks and Regards,
Vardhan Desai 19-Feb-13 2:15am
No absolutely you cannot. Primary Key is a identifier for a record. Primary Key is better to be numeric.
Plz read the concept of Primary Key before implementation.
Vardhan Desai 19-Feb-13 4:41am
Is it working now?
Member 8054539 19-Feb-13 7:19am
i don't know how to do?

i am trying the below thing as follows;

in the database can i add one column SNo.

And set the SNo to Primary key.

when i update, i use the above query as follows;

sql = "Update Tb_common_Holidays set [Day] = '" + cb_daysweek.Text + "' where SNO = '" + cb_id.Text + "' ";

The above Update query is correct and please help me.

but in design i won't show the SNO.
Only in Database SNO will be there.

For SNO i use datatype as Auto Number.
Vardhan Desai 21-Feb-13 7:04am
Is your problem solved?
If with my slution then do 'Accept Solution'
Else let me know atlst.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Yeah. . . SNo should be Primary Key with datatype Numeric/Integer.
Fetch SNo in an Hiddenfield (Control from ToolBox) while listing the details.
used the same in Where Clause of Update Clause.
Initially Hiddenfield will be blank. And its Property is ".Value" to Save text in it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100