So im trying to learn c# because i want to change my old programming skill which is vb.net im opening some converter site but it doesn't work. I just want to know the code of USING and WITH in vb.net to c#.
here's my code in vb.net:
Dim rand As New Random
abuildnumber.Text = rand.Next
Dim exist As String = String.Empty
exist &= "select * from stocks "
exist &= "where build_number=@build"
Using conn As New SqlConnection("server=WIN10;user=admin;password=12345;database=pc_parts")
Using cmd As New SqlCommand
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandText = exist
.Parameters.AddWithValue("@build", abuildnumber.Text)
End With
Try
conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader
If reader.HasRows Then
reader.Close()
abuildnumber.Text = rand.Next
End If
abrand.Enabled = True
apart.Enabled = True
aquantity.Enabled = True
aday.Enabled = True
amonth.Enabled = True
ayear.Enabled = True
add.Enabled = True
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Using
End Sub