.net
  • database
  • vb.net
  • ms-access
  • 2016-06-08 1 views -1 likes 
    -1

    Access 데이터베이스에 항목이 이미 있는지 확인하고 싶습니다. 그리고 내 연구를 통해이 코드를 얻는 데 성공했지만 오류가 발생했습니다. 원하는 코드를 달성하는 데 올바른 방향으로 나를 안내 할 수 있습니까? 여기 .NET에서 Access에 중복 항목이 있는지 확인하십시오.

    내 코드입니다 :

    Dim commandText = "SELECT COUNT(*) AS FROM ESRRegister WHERE ID = '" & IDtxt.Text & "'" 
        Using (conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database\Database.accdb")) 
         Using ("select = New OleDbCommand(commandText, conn)") 
          conn.open() 
          Dim count = Convert.ToInt32("select.ExecuteScalar()") 
          If count > 0 Then 
           MessageBox.Show("Already Exists!", "ALI ENTERPRISES", MessageBoxButtons.OK, MessageBoxIcon.Information) 
          Else 'Your insert code cmd.CommandText = "insert into ESRRegister (Dt,ID)VALUES ('" & Dttxt.Text & "' , '" & IDtxt.Text & "')" queryResult = cmd.ExecuteScalar() MsgBox("Added Successfuly") 
          End If 
         End Using 
        End Using 
    

    내가

    가 대단히 감사합니다 .NET에 새로 온 사람 bcoz 당신이 코드에 대한 약간의 설명을 제공하는 경우 그것은 좋은 것

    +0

    어떤 오류가 발생합니까? 어떤 라인에서? – marlan

    +0

    2 번째 줄에서 ... "(conn"...........를 사용하면 ... conn는 ....입니다. conn이 선언되지 않았다고 말합니다. – winnu

    +0

    는 나에게 "사용 중"인 것처럼 보입니다. 'OleDbCommand'와'Convert.ToInt32' 문법이 틀리다. – marlan

    답변

    0
    'The SQL instruction as a string 
    commandText = "SELECT COUNT(*) AS FROM ESRRegister WHERE ID = '" & IDtxt.Text & "'" 
    'Open the connection to the Database 
    Connection.Open() 
        'Use the SQLinstruction to create an OleDBcommand 
        Dim mySQLCommand As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand(commandText, Connection) 
        'Perform the SQL-instruction 
        Dim count as integer = CInt(mySQLCommand.ExecuteScalar) 
        mySQLCommand.Dispose() 'Clean the command object 
    Connection.Close() 'Close/Clean connection 
    
    +0

    안녕하세요, 코드 주셔서 감사합니다 ..하지만 난 MS 액세스 및 SQL이 필요합니다 – winnu

    0
    Dim commandText As String = "SELECT NZ(COUNT(*),0) FROM ESRRegister WHERE ID = '" & IDtxt.Text & "'" 
    Using conn as New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database\Database.accdb") 
    dim Cmd As New OleDbCommand(commandText, conn 
        conn.open() 
        Dim count as intiger = Convert.ToInt32(Cmd.ExecuteScalar()) 
        If count > 0 Then 
         MessageBox.Show("Already Exists!", "ALI ENTERPRISES", MessageBoxButtons.OK, MessageBoxIcon.Information) 
        Else 
         cmd.CommandText = "insert into ESRRegister (Dt,ID)VALUES ('" & Dttxt.Text & "' , '" & IDtxt.Text & "')" 
         Dim queryResult as Variant = cmd.ExecuteNonQueryr() 
         MsgBox("Added Successfuly") 
        End If 
    End Using 
    

    select는 VB.net에 저장된 단어, 나는 OleDbCommand의 이름을하는 변경 Cmd

    관련 문제