Dim x As Integer, price As Integer
Dim cmd As New SqlCommand("Select Fieldname from Tablename", objConn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read() Then
Dim d As String = dr(0).ToString()
If d = "" Then
price = Convert.ToInt32(txtprice.Text)
price = price / 100
txtpoint.Text = price.ToString()
Else
x = Convert.ToInt32(dr(0).ToString())
price = Convert.ToInt32(txtprice.Text)
x = x + price
txtpoint.Text = x.ToString()
End If
End If
objConn.Close()
objConn.Open()
cmd.CommandText = "insert Tablename(fieldname) values('" + txtpoint.Text + "')"
cmddExecuteNonQuery()
Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class FormEdit
Dim strID As String = ""
Public Property _strID() As String
Get
Return strID
End Get
Set(ByVal value As String)
strID = value
End Set
End Property
Private Sub FormEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myConnection As SqlCeConnection
Dim dt As New DataTable
Dim Adapter As SqlCeDataAdapter
'myConnection = New SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\Database1.sdf;"))
myConnection = New SqlCeConnection("Data Source=E:\sasitornpro\sasitornpro\MyDatabase#1.sdf;")
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "SELECT [member_id], [member_name], [member_address],[member_count] FROM [member] WHERE member_id = '" & strID & "' "
myCommand.CommandType = CommandType.Text
Adapter = New SqlCeDataAdapter(myCommand)
Adapter.Fill(dt)
myConnection.Close()
If dt.Rows.Count > 0 Then
Me.TxtId.Text = dt.Rows(0)("member_id")
Me.TxtName.Text = dt.Rows(0)("member_name")
Me.TxtAddress.Text = dt.Rows(0)("member_address")
Me.TxtCount.Text = dt.Rows(0)("member_count")
End If
dt = Nothing
End Sub
Private Sub BtSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtSave.Click
If Me.TxtId.Text = "" Then
MessageBox.Show("กรุณาใส่รหัสสมาชิก (member_id)")
Me.TxtId.Focus()
Exit Sub
End If
If Me.TxtName.Text = "" Then
MessageBox.Show("กรุณาใส่ชื่อ (member_name)")
Me.TxtName.Focus()
Exit Sub
End If
If Me.TxtAddress.Text = "" Then
MessageBox.Show("กรุณาใส่ที่อยู่ (member_address)")
Me.TxtAddress.Focus()
Exit Sub
End If
If Me.TxtCount.Text = "" Then
MessageBox.Show("กรุณาใส่แต้มสะสม (member_count)")
Me.TxtCount.Focus()
Exit Sub
End If
Dim myConnection As SqlCeConnection
'myConnection = New SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\Database1.sdf;"))
myConnection = New SqlCeConnection("Data Source=E:\sasitornpro\sasitornpro\MyDatabase#1.sdf;")
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "UPDATE [member] SET " & _
" [member_id] = '" & Me.TxtId.Text & "', [member_name] = '" & Me.TxtName.Text & "' ,[member_address] = '" & Me.TxtAddress.Text & "',[member_count] = '" & Me.TxtCount.Text & "' " & _
" WHERE member_id = '" & strID & "' "
myCommand.CommandType = CommandType.Text
myCommand.ExecuteNonQuery()
myConnection.Close()
MessageBox.Show("อัพเดทข้อมูลสำเร็จ")
Me.Hide()
Dim f As New Member
f.Show()
End Sub
Private Sub BtExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtExit.Click
Me.Hide()
Dim f As New Member
f.Show()
End Sub
Private Sub BtEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TxtId_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtId.TextChanged
End Sub
Private Sub TxtCount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtCount.TextChanged
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtPrice.TextChanged
End Sub
End Class