使用参数代码的正确方法是什么,以及选择datagridview数据和移动到文本框的正确方法是什么? [英] What is the proper way of using parameter code and the proper way to select datagridview data and move to textbox?

查看:85
本文介绍了使用参数代码的正确方法是什么,以及选择datagridview数据和移动到文本框的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是我的新手,但我真正理解并使用ms access在vb.net中学习正确的代码方式。请以示例教我。



关于参数什么是正确的方法或最好使用?

I am just I newbie but I really what to understands and learn the proper way of codes in vb.net using ms acces. Kindly teach me with example.

about Parameters what is the right way or best to use?

cmd.Parameters.Add(New OleDb.OleDbParameter("@ID", OleDbType.Numeric)).Value =
TextBox1.Text

cmd.Parameters.Add(New OleDbParameter("ID", CType(TextBox1.Text, String)))





关于选择datagridview将数据移动到文本框什么是正确的一个还是另一个正确的方式?



about selecting datagridview to move the data to textbox what is the right one or is there a other way the right one?

TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value
 TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString()





我尝试过:



使用此代码,但我很困惑有什么区别?或者正确使用?



What I have tried:

using this code but i am confuse what's the difference? or the right one to use?

推荐答案

对于添加参数,我更喜欢更短的方式:

For adding parameters, I prefer a shorter way of:
cmd.Parameters.AddWithValue("ID", TextBox1.Text)
cmd.Parameters.AddWithValue("DOB", DatePicker1.Value.Date)



这样,它保留了数据类型。



关于选择datagridview单元格值:


That way, it preserves the datatype.

About selecting datagridview cell value:

Dim row As DataGridViewRow = DataGridView1.Rows(x)
TextBox1.Text = row.Cells(clmID.Index).Value



- x是我们想要的行的索引号复制到文本框。

- clmID是DataGridViewColumn的名称,我更喜欢这种方式,所以当我决定明天移动列顺序时,我不会打扰列inde x了。


- x is the index number of the rows we want to copy to textbox.
- clmID is the name of the DataGridViewColumn, I prefer this way so that when I decide to move the column ordering tomorrow, I won't bother with the column index anymore.


这篇关于使用参数代码的正确方法是什么,以及选择datagridview数据和移动到文本框的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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