我在Access 2010中有一个名为Clienti
的DB表,列:
-
nume
(text) -
prenume
(text) -
cnp
(number) -
varsta
(number) -
adresa
(text) -
localitate
(text) -
data
(date) -
stare
civila (text) -
venit
(number) -
tipcreditales
(text) -
rezultat
(text)
numarcopii
(number)我做了一个窗体在VB。. NET使用Visual Studio 2013,我想插入数据到Clienti
表。
我的问题是:
-
对于
data
我使用日期/时间选择器。我能把它转换成日期吗?当我尝试插入它时,VB说日期/时间选择器不能转换为日期。 -
对于
stare civila
,我想要一个组合框与3项一起使用。我如何将这3个项目转换为字符串?(项目由我手工介绍) -
对于
tipcreditales
,我也想使用一个组合框,所以同样的问题可以应用
使用的代码是:
Convert.ToInt32(cnptxt.Text)
Convert.ToInt32(numarcopiitxt.Text)
Dim cnpp As Integer
cnpp = Val(cnptxt.Text)
Dim nrcopii As Integer
nrcopii = Val(numarcopiitxt.Text)
Dim nume As String
Dim prenume As String
Dim cnp As Integer
Dim varsta As Integer
Dim adresa As String
Dim localitate As String
Dim starecivila As String
Dim numarcopii As Integer
Dim data As Date = datatxt.Value.Date
Dim venit As Integer
Dim tipcreditales As String
Dim rezultat As String
nume = numetxt.Text
prenume = prenumetxt.Text
cnp = cnpp
varsta = varstatxt.Text
adresa = adresatxt.Text
localitate = localitatetxt.Text
starecivila = starecivilatxt.Text
numarcopii = numarcopiitxt.Text
tipcreditales = ComboBox1
rezultat = rezultattxt.Text
If Me.ClientiTableAdapter.InsertQueryClienti(nume, prenume, cnp, varsta, adresa, localitate, starecivila, numarcopii, tipcreditales, rezultat) Then
MsgBox("Adaugat cu succes in baza de date!")
End If
当试图运行应用程序时,它说:
1"System.Windows.Forms"类型的值。"组合框"不能转换为"字符串"。D:Testincercare2WindowsApplication2WindowsApplication2Form3.vb 60 25 WindowsApplication2
2参数'rezultat'的公共可重写的重载函数InsertQueryClienti(名称作为字符串,前缀作为字符串,cnp作为整数?, varsta为整数?地址为字符串,位置为字符串,数据为日期?, stare_civila作为字符串,numarcopii作为整数?, venit As String, tipcreditales As String, rezultat As String) As Integer'。D:Testincercare2WindowsApplication2WindowsApplication2Form3.vb 62 12 WindowsApplication2
3参数'tipcreditales'的公共可重写重载函数InsertQueryClienti(名称作为字符串,前缀作为字符串,cnp作为整数?, varsta为整数?地址为字符串,位置为字符串,数据为日期?, stare_civila作为字符串,numarcopii作为整数?, venit As String, tipcreditales As String, rezultat As String) As Integer'。D:Testincercare2WindowsApplication2WindowsApplication2Form3.vb 62 12 WindowsApplication2
InsertQueryClienti的代码
`Public Overridable Overloads Function InsertQueryClienti(
ByVal nume As String
ByVal prenume As String
ByVal cnp As Global.System.Nullable(Of Integer)
ByVal varsta As Global.System.Nullable(Of Integer),
ByVal adresa As String,
ByVal localitate As String,
ByVal data As Global.System.Nullable(Of Date)
ByVal stare_civila As String,
ByVal numarcopii As Global.System.Nullable(Of Integer),
ByVal venit As String,
ByVal tipcreditales As String,
ByVal rezultat As String) As Integer`
获取DateTimePicker值的方法如下:
Public Sub New()
' Create a new DateTimePicker
Dim dateTimePicker1 As New DateTimePicker()
Controls.AddRange(New Control() {dateTimePicker1})
MessageBox.Show(dateTimePicker1.Value.ToString())
dateTimePicker1.Value = DateTime.Now.AddDays(1)
MessageBox.Show(dateTimePicker1.Value.ToString())
End Sub 'New
下面是获取ComboBox值的方法:
Private Sub showSelectedButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim selectedIndex As Integer
selectedIndex = comboBox1.SelectedIndex
Dim selectedItem As Object
selectedItem = comboBox1.SelectedItem
MessageBox.Show("Selected Item Text: " & selectedItem.ToString() & Microsoft.VisualBasic.Constants.vbCrLf & _
"Index: " & selectedIndex.ToString())
End Sub