0 Replies - 788 Views - Last Post: 09 March 2013 - 11:32 AM Rate Topic: -----

#1 aw350me89   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 07-March 13

insert specific user sata from vs2012 to sql

Posted 09 March 2013 - 11:32 AM

Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Public Class Create_Profile
    Dim MySqlConnection As MySqlConnection
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MySqlConnection = New MySqlConnection("server details have been removed")
'this part I am trying to select a specific user that I want to update
        Dim sqlquery As String = "SELECT * FROM Users WHERE Username = '" + Login.UsernameTextBox.Text + "';"
        Dim data As MySqlDataReader
        Dim adapter As New MySqlDataAdapter
        Dim command As New MySqlCommand
        command.CommandText = sqlquery
        command.Connection = MySqlConnection
        adapter.SelectCommand = command
        data = command.ExecuteReader
        If sqlquery = True Then
'Ths part I am trying to insert data into the specific user  in sql
            Dim sqlquery2 As String = "INSERT INTO Users (sName, fName)VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "')"
            Dim data2 As MySqlDataReader
            Dim adapter2 As New MySqlDataAdapter
            Dim command2 As New MySqlCommand
            command2.CommandText = sqlquery2
            command2.Connection = MySqlConnection
            adapter2.SelectCommand = command2
            data2 = command2.ExecuteReader
            MsgBox("Profile Updated")
        End If
    End Sub
End Class

So overall I am try to allow a user to be able to update their user info in sql and later the data will be retrieved and displayed in a different form.

At the moment when I try to run this (obviously with server details) it adds data but as a new user that has no other details.

8 - id
NULL - Username
NULL -Password
m - fName
m- sName

9 - id
NULL - Username
NULL -Password
m - fName
m- sName

There may be a simple solution to this but i dont know lol.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1