我想做一个用类的对象填充我的数据库的函数 [英] i want to make a function that populate my database with objects of the class
本文介绍了我想做一个用类的对象填充我的数据库的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我到目前为止所做的,但是现在不完成该功能
this is what i made until now but a don''t now to finish the function
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Public Class Salariat
Dim m_cnp As String
Dim m_nume As String
Dim m_prenume As String
Dim m_adresa As String
Dim m_telefon As String
Dim m_calificare As String
Dim m_contBancar As String
Public Property cnp() As String
Get
Return m_cnp
End Get
Set(ByVal value As String)
If Len(value) = 13 Then
m_cnp = value
Else
Throw New Exception("CNP incorect!")
End If
End Set
End Property
Public Property nume() As String
Get
Return m_nume
End Get
Set(ByVal value As String)
If value <> "" Then
m_nume = value
Else
Throw New Exception("Completati Numele!")
End If
End Set
End Property
Public Property prenume() As String
Get
Return m_prenume
End Get
Set(ByVal value As String)
If value <> "" Then
m_prenume = value
Else
Throw New Exception("Completati Prenumele!")
End If
End Set
End Property
Public Property adresa() As String
Get
Return m_adresa
End Get
Set(ByVal value As String)
m_adresa = value
End Set
End Property
Public Property telefon() As String
Get
Return m_telefon
End Get
Set(ByVal value As String)
m_telefon = value
End Set
End Property
Public Property calificare() As String
Get
Return m_calificare
End Get
Set(ByVal value As String)
m_calificare = value
End Set
End Property
Public Property contBancar() As String
Get
Return m_contBancar
End Get
Set(ByVal value As String)
If Len(value) = 24 Then
m_contBancar = value
Else
Throw New Exception("Cont bancar incorect!")
End If
End Set
End Property
Public Sub Adauga()
Dim cmd As New SqlCommand
Dim sCnnection As String = "server=(local);Integrated Security=SSPI;database=crossal"
Dim cnn As New SqlConnection With {.ConnectionString = sCnnection}
cnn.Open()
cmd.Connection = cnn
End Sub
End Class
推荐答案
您需要首先设计数据库表结构.
完成后,您需要将此处拥有的属性的值保存到数据库中.
在互联网上进行搜索.有大量的文章对此进行了描述.
试试看.如果遇到任何问题,请在此处发布.
You need to design the database table structure first.
Once that is done, you need to save the values of the properties you have here into the database.
Do a search on the internet. There are tons of articles describing this.
Try something out. If you run into any issues, post them here.
尝试以下操作:
Try this:
Public Sub Adauga()
Dim cmd As New SqlCommand
Dim sCnnection As String = "server=(local);Integrated Security=SSPI;database=crossal"
Dim cnn As New SqlConnection With {.ConnectionString = sCnnection}
cnn.Open()
cmd.Connection = cnn
cmd.CommandText = "INSERT INTO tableName (CNP, Nume, Prenume, Adresa, Telefon, Calificare, Contbancar) VALUES (@CNP, @Nume, @Prenume, @Adresa, @Telefon, @Calificare, @Contbancar)"
cmd.Parameters.AddWithValue("@CNP", Me.cnp)
cmd.Parameters.AddWithValue("@Nume", Me.nume)
''Add rest of members as parameters like this
cmd.ExecuteNonQuery()
cnn.Close()
End Sub
希望对您有帮助
Hope this helps
这篇关于我想做一个用类的对象填充我的数据库的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文