Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Copy value From table to onther table in same Database in VS2010


Copy value From table to onther table in same Database in VS2010

Author
Message
AbdelazizOmar
AbdelazizOmar
Junior Member
Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)

Group: Forum Members
Posts: 1, Visits: 1
Hey Guys i need to copy value from table to onther table in same data base

like.. My program is to Add Silk Or Money into database by the user write the username into textbox1 and the amount of silk or money into textbox2 and the record need a value from onther database i need to find that value from Username..



need JID

i need to Get JID From StrUSerID Then Put the the JID Into onther table by write the StrUserID into textbox1 and amount silk or money into textbox2







then put it here





but i got dat error





Insert into data code:

Query = "insert into SK_Silk (JID,silk_own) Values ('" & TextBox1.Text & "' , '" & TextBox2.Text & "') Select JID From TB_User where JID='" & TextBox1.Text & "'"




full code:

Imports System.Data.SqlClient

Public Class addsilk

Public mysqlconn As SqlConnection

Public command As SqlCommand









Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

mysqlconn = New SqlConnection

mysqlconn.ConnectionString = "Data Source=" + Form2.txtServerName.Text + ";initial catalog=" + Form2.txtdatabasename.Text + ";user id=" + Form2.textusername.Text + ";password=" + Form2.txtpassword.Text



Dim reader As SqlDataReader





Try





mysqlconn.Open()

Dim Query As String





Query = "insert into SK_Silk (JID,silk_own) Values ('" & TextBox1.Text & "' , '" & TextBox2.Text & "') Select JID From TB_User where JID='" & TextBox1.Text & "'"



command = New SqlCommand(Query, mysqlconn)

reader = command.ExecuteReader

' NotifyIcon1.ShowBalloonTip(1000, "Information", "Has Been added Silk To" & TextBox2.Text, ToolTipIcon.Info)

NotifyIcon1.ShowBalloonTip(1000, "Information", " Has Been Add " & TextBox2.Text & " Silk To " & TextBox1.Text, ToolTipIcon.Info)

'MessageBox.Show(" Has Been Added " & TextBox2.Text & " Silk To Username " & TextBox1.Text)

mysqlconn.Close()







Catch ex As Exception

MessageBox.Show(ex.Message)







End Try





End Sub



Edited
2/24/2016 by AbdelazizOmar
zack
zack
Forum God
Forum God (690 reputation)Forum God (690 reputation)Forum God (690 reputation)Forum God (690 reputation)Forum God (690 reputation)Forum God (690 reputation)Forum God (690 reputation)Forum God (690 reputation)Forum God (690 reputation)

Group: Forum Members
Posts: 102, Visits: 110
I think you are getting this error because you are trying to write an character string into an Integer field in your database.



Query = "insert into SK_Silk (JID,silk_own) Values ('" & TextBox1.Text & "' , '" & TextBox2.Text & "') Select JID From TB_User where JID='" & TextBox1.Text & "'"





JID is of type Integer, and the value in TextBox1.Text is a character string. For this reason you are getting a type mismatch.
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search