473,466 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Updating individual fields from a row in LINQ

1 New Member
Hi,

I am trying to update 3 individual fields from a row in my database using LINQ. I have to enter a student id when the page runs then this matches their record in the database and populates the gridview with the 3 fields that i want to edit. Is their any way to do this? So far i have this,

Expand|Select|Wrap|Line Numbers
  1. Protected Sub SubBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubBtn.Click
  2.  
  3. Dim number = txtStudentID.Text
  4.  
  5. Dim db As New OrionDataClassesDataContext()
  6.  
  7.  
  8. Dim match = From u In db.Users
  9. Where u.User_Number = number
  10. Select u.Contact_number, u.Home_address, u.Term_address
  11.  
  12. GridView1.DataSource = match
  13. GridView1.DataBind()
  14.  
  15. End Sub
Any help much appreciated.
Thanks,
Michael
Apr 12 '13 #1
1 1194
vijay6
158 New Member
Hey Mhogshaw, Create a new button. Once if that button was clicked then connect to your database and update fields like as follows,


Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click(sender As Object, e As EventArgs)
  2.     Try
  3.         Dim con As New SqlConnection("Your database connection string")
  4.  
  5.         For i As Integer = 0 To dataGridView1.Rows.Count - 1
  6.  
  7.             Dim cmd As New SqlCommand("UPDATE Users SET 
  8.             Contact_number = '" + dataGridView1.Rows(i).Cells(0).Value.ToString() + "', 
  9.             Home_address = '" + dataGridView1.Rows(i).Cells(1).Value.ToString() + "', 
  10.             Term_address = '" + dataGridView1.Rows(i).Cells(2).Value.ToString() + "' 
  11.             WHERE User_Number = '" + txtStudentID.Text + "'", con)
  12.  
  13.             con.Open()
  14.             cmd.ExecuteNonQuery()
  15.         Next
  16.  
  17.         MsgBox("Updated")
  18.     Catch ex As Exception
  19.         MsgBox(ex.ToString())
  20.     Finally
  21.         con.Close()
  22.     End Try
  23. End Sub
Apr 15 '13 #2

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

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
2
by: Ironman | last post by:
Dear Access Developers: I have an interesting problem that I hope someone could suggest how to solve: I have the following Report: Col-1 Col-2 -------- ------- 483.3 100
1
by: Holly55 | last post by:
I have created a database and wish to lock individual fields so that once information has been entered, it cannot be changed. I have done this through an event procedure... Private Sub...
1
by: thandiwe | last post by:
may somebody help me, i am working on an access database and my tables have related fields. i want these fields to update at once after updating one of them..the fields have formulas, so i would...
1
by: alejo | last post by:
i know i should not be asking..... but i am! ok, i am trying to make a simple database (real Simple) it will store publications, just the volume and issue numbers and also their print cycle (ie....
5
by: mpundu | last post by:
This is my form: =========================== <% form_tag :action => 'update', :id => @book.id, :title => @book.title, :price => @book.price, :description => @book.description %> <%= render...
4
by: parkergirl | last post by:
Hello, I am currently working on a project that has many tabs all on one form. Since you can only have so many controls on one form, my job is to seperate these tabs into forms. One problem that I...
1
by: Krishna | last post by:
How do I access individual fields in csv using python? Please let me know ASAP as its real urgent for me. Thanks for your help Krishna
1
balabaster
by: balabaster | last post by:
Does anyone have experience integrating LINQ into SOA architecture. I've spent all night trawling through documents and books regarding this and I've come to the conclusion that I'm going about...
3
by: kate2272 | last post by:
Hi Guys I was wondering if it is possible to turn AllowEdits to false after data has been entered for individual fields within a form/sub-form. I've found that I can do this in the 'AfterUpDate'...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.