Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have the following code that executes on the click of a Button ... I know it's probably poor coding and inefficient, but I am just trying to get my logic working before I worry about performance and naming standards. Anyway, after I have read and selected the Folder I want, how do I update the SQL Server Table with the new Path I've selected ?

VB
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click

     Dim folderBrowserDialog As New FolderBrowserDialog()

     myPath = Environment.SpecialFolder.MyComputer

     Me.FileLocationsTableAdapter1.Fill(Me.KickaboutEmailDataSet1.FileLocations)

     For Each Dr As DataRow In KickaboutEmailDataSet1.FileLocations.Rows
         myPath = Dr.Item(1).ToString
     Next

     folderBrowserDialog.Description = "Select Folder Where Despatch Schedule File is Stored"
     folderBrowserDialog.RootFolder = myPath
     folderBrowserDialog.ShowNewFolderButton = True

     If folderBrowserDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
         myPath = folderBrowserDialog.SelectedPath
     Else
         Exit Sub
     End If

    >>> Now I need to update the Database with the new Path <<<


 End Sub
Posted
Comments
So, what is the issue?

1 solution

You should worry about naming standards from the start, or you'll never get it right. Over time, you can also learn how to write more performant code.

How are you using the DB in the first place ? If you're learning, Entity Framework is what is easiest to work with, you won't need to learn SQL for a start. Your options are

1 - EF ( easiest )
2 - stored procs
3 - a paramaterised query
 
Share this answer
 
Comments
Gary Heath 22-Jan-14 11:56am    
Yes, you are right, of course, Christian, but this is a very small application that I just need to get working ASAP & I will be updating my naming very soon ... the reason I haven't been strict at this point in time is because this is my third different attempt at doing this and I have wasted so much time over the past 2 making sure my names are right and then having to (well, CHOOSING to) start again that I decided I would get the basics working first !!!

Previously I have accessed my databases by having a ConnectionString and passing SQL statements, somebody suggested I use this method, as it automatically updates my ComBobox & Data Tables and I have to say, for READING of the database it is simplicity itself. However, this is where I fall foul of a lack of understanding which prompted the question above, using this method, how do I WRITE to the database ?
Christian Graus 22-Jan-14 16:35pm    
I guess at the end of the day, once you have a little experience, good naming practice will happen automatically. But that will come sooner if you work at it.

You write to the DB the same way you read from it. You create SQL commands and you execute them. http://www.codeproject.com/Articles/16994/Use-SQL-Parameters-to-Overcome-Ad-Hoc-Performance is an article on how to do this.
Gary Heath 22-Jan-14 18:49pm    
I am actually off to bed without checking your link, Christian, I'll take a look in the morning, BUT ... I haven't used any SQL commands, that is why I am confused and a bit lost ... all I have done to read the data is use these .FILL commands, there is no SQL in my program !!!
Christian Graus 22-Jan-14 18:53pm    
Ah... then your SQL is being automatically generated for you. You can't talk to a database without SQL, if you write it or not. The easiest way to avoid SQL, is to use Entity Framework, that will create classes based on your DB structure, and you can create instances, and add them to your DB. That's what I recommend learning.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900