我想做一个用类的对象填充我的数据库的函数

我想做一个用类的对象填充我的数据库的函数

本文介绍了我想做一个用类的对象填充我的数据库的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我到目前为止所做的,但是现在不完成该功能

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

推荐答案


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


这篇关于我想做一个用类的对象填充我的数据库的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 20:18