Datagridview并根据datagridview中的第一列更新sqlce表 [英] Datagridview and update the sqlce table based on first column in the datagridview

查看:97
本文介绍了Datagridview并根据datagridview中的第一列更新sqlce表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我在编程方面相当新鲜。如果可能的话,我正在寻求一些帮助。

我现有的员工表中有员工的详细信息,期望现在有一列闪烁。我的目标是更新该闪烁列中的文件夹路径以及徽章编号(徽章编号将是文件夹中员工图片的标识符)。



由于数据已经存储在表格中,逐个更新需要时间。如何使用文件夹路径+ EmpID更新表格?



Datagridview第一列是EmpID。因此,无论第一列中的EmpID应与文件夹路径一起分配,以实现我的目标。



我尝试过:



 Private Sub Button2_Click(发送者为对象,e为EventArgs)处理Button2.Click 
'获取照片路径的文件夹仅
Dim fbd As New FolderBrowserDialog
fbd.RootFolder = Environment.SpecialFolder.MyComputer
if fbd.ShowDialog = DialogResult.OK Then
TextBox1.Text = fbd.SelectedPath
End If
结束次级





私人子按钮3_Click(发件人为对象,e为EventArgs)处理Button3.Click 
Dim con As New SqlCeConnection
Dim cmd As New SqlCeCommand
Try
con.ConnectionString =Data Source = C:\ Users \ User.Documents \ Visual Studio 2012 \Projects\HSEDB-Oman \ HSEDB-Oman \ HSEDBOman.sdf
con.Open()
cmd.Connection = con
cmd.CommandText =更新到tblemployee(ImagePath)VALUES('& TextBox1.Text& ')'Textbox1是文件夹路径持有者
cmd.ExecuteNonQuery()

Catch ex As Exception
MessageBox.Show(在表格上插入记录时出错... & ex.Message,插入记录)
最后
con.Close()
结束尝试
结束子





我只想在ImagePath列中一起添加文件夹路径+ EmpID,所以当我保留该文件夹中员工的图片时,将会通读并在将来显示在表单中。



示例文件夹路径:

C:\ Users \User \Desktop\EmployeePicture\124268.jpg



非常感谢

Tamang

解决方案

您的SQL命令更新进入tblemployee ... 似乎不是一个有效的SQL语句。

它应该是这样的:

 < span class =code-keyword> UPDATE  tblemployee  SET  Ima gePath = '  tralalala' 



in your代码是:

UPDATE tblemployee set ImagePath ='& Me.TextBox1.Text& 'WHERE EmpID ='124268'



另见这里的例子: SQL UPDATE语句 [ ^ ]


Dear all,

I am pretty new in the programming. I'm looking for some help if possible.
I have my existing employee table with employee's details expect one column which is blink right now. My goal is to update folder path in that blink column along with badge number (badge number will identifier of employee picture in the folder).

Since the data are already stored in the table, it will take time to update one by one. How can i update the table with the folder path + EmpID?

Datagridview first column is EmpID. So whatever the EmpID in the first column should be assigned together with folder path to achieve my goal.

What I have tried:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    'Get folder of photo path only
    Dim fbd As New FolderBrowserDialog
    fbd.RootFolder = Environment.SpecialFolder.MyComputer
    If fbd.ShowDialog = DialogResult.OK Then
        TextBox1.Text = fbd.SelectedPath
    End If
End Sub



Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim con As New SqlCeConnection
    Dim cmd As New SqlCeCommand
    Try
        con.ConnectionString = "Data Source=C:\Users\User\Documents\Visual Studio 2012\Projects\HSEDB-Oman\HSEDB-Oman\HSEDBOman.sdf"
        con.Open()
        cmd.Connection = con
        cmd.CommandText = "Update Into tblemployee(ImagePath)VALUES('" & TextBox1.Text & "')" ' Textbox1 is folder path holder
        cmd.ExecuteNonQuery()

    Catch ex As Exception
        MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
    Finally
        con.Close()
    End Try
End Sub



I just want to add folder path + EmpID together in the ImagePath column, so when i keep picture of employee in that folder will read through and display in the form in the future.

Example folder path:
C:\Users\User\Desktop\EmployeePicture\124268.jpg

Thanks a lot
Tamang

解决方案

Your SQL command Update Into tblemployee ... does not seem to be a valid SQL statement.
It should be something like:

UPDATE tblemployee SET ImagePath = 'tralalala'


in your code it would be:

"UPDATE tblemployee set ImagePath = '" & Me.TextBox1.Text & "' WHERE EmpID = '124268'" 


Also see examples here: SQL UPDATE Statement[^]


这篇关于Datagridview并根据datagridview中的第一列更新sqlce表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆