Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help Creating a function to change SQL Field Values

Posted on 2007-11-18
1
Medium Priority
?
148 Views
Last Modified: 2011-09-20
Hi all

Im looking for some help in creating a function to allow me to hardcode updates into SQL. The attached code will allow me to open the DB and search the fields however its been a while since ive programmed in vb and am moving to .net so hence the .field("Name") = is a bit out of date..  :)

Any help would be great

Many Thanks
Steve

Code in use __________________________________
       Dim SQL As String = "SELECT * FROM USERINFO WHERE USERNAME = '" & txtUsername.Text & "' AND PASSWORD  = '" & CryptPass & "'"
        Dim sqlReader As SqlDataReader = CCDBC.CCDBC.RetrieveData(SQL)
 
        If sqlReader.Read Then
            With sqlReader
                MsgBox(.GetValue(1) & "   " & .GetValue(2) & "   " & .GetValue(3))
            End With
            Me.Close()
        Else
            MsgBox("Invalid Username or Password entered", MsgBoxStyle.Exclamation)
        End If
        sqlReader.Close()
        sqlReader = Nothing
 
__________________________________________________
 
 
 
 
Public Shared Function GetConnection() As SqlClient.SqlConnection
        Dim conn As SqlClient.SqlConnection
        Dim strConn As String = "Data Source=SQLEXPRESS;Initial Catalog=CC;Integrated Security=True;Pooling=False"
 
        conn = New SqlClient.SqlConnection(strConn)
        Try
            conn.Open()
        Catch ex As SqlClient.SqlException
            Console.WriteLine("SQL Server ERROR: " & ex.Message & " in " & ex.StackTrace)
 
        Catch ex As Exception
            Console.WriteLine("ERROR opening connection: " & ex.Message)
        End Try
        GetConnection = conn
    End Function
 
    Public Shared Function RetrieveData(ByVal query As String) As SqlClient.SqlDataReader
        Dim rdr As SqlClient.SqlDataReader
        Dim conn As SqlClient.SqlConnection = GetConnection()
        Try
            Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(query, conn)
            ''CommandBehavior.CloseConnection closes the underlying connection 
            ''whenever the reader is closed
            rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        Catch ex As SqlClient.SqlException
            Console.WriteLine("SQL Server ERROR: " & ex.Message & " in " & ex.StackTrace)
        Catch ex As Exception
            Console.WriteLine("ERROR retrieving data: " & ex.Message)
        End Try
        RetrieveData = rdr
    End Function

Open in new window

0
Comment
Question by:Stephen Manderson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 20310503
please check out this tutorial:
http://webgraphics.web108.discountasp.net/HandH/AdapterUpdate.htm

it tells you to fill in a sqldataadapter, and define the UpdateCommand that will submit the sql update (or procedure) to save any changes done to the data inthe sqldataadapter...

hope this clarifies how to do things the .net way
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question