Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 READING DATA

Author  Topic 

yalcin
Starting Member

1 Post

Posted - 2006-02-03 : 11:00:22
Hi,

I am writing a small program with vb.net with connectig to the mdb database. I have problem that i could not solve.

I have three tables which are;
ROLE(ROLEID,ROLEADI) -->ROLEADI=ROLENAME
FONKSIYON(FONKSIYONID,DONKSIYONADI) -->FONKSIYONADI=FONKSIYONNAME
IDKARSILASTIR(ROLEID,FONKSIYONID) -->"comparing"

I have devices and they have functions in them. Some of them consist 1 some of them consists more then 1 functions. So I create CATAGORY(catID,devID,funcID) table to compare the deviceID and functionID.

I took the functionNAMEs from database and show them using checkboxlist object to the user. If user selects any function in checkbox, OK..., it works and takes the name of the device which this selected checkbox function. But If the user select the second function my problem begin. I must show the device names which has consist all the functions that the user selected. For Example:if any device has 21 and 22 functions and if the user has selected this functions from the checkboxlist object I must show the device names which consist the 21 and 22 functions in them.

My sql does wrong. It gives the device names consisting 21,22, and both 21 and 22 functions.

MY CODE IS:
-----------

Try
Dim sorguKisim1 As String = ""
Dim sorguKisim2 As String = ""
Dim sorguRoleID As String = ""
Dim i As Byte = 0
'******************************************************************
sorguKisim1 = "SELECT ROLE.ROLEADI FROM ROLE INNER JOIN IDKARSILASTIR ON ROLE.ROLEID = IDKARSILASTIR.ROLEID WHERE( "
'sorguKisim1 = "SELECT ROLE.ROLEADI FROM ROLE WHERE( "
For i = 0 To ChkBoxListFonklar.Items.Count - 1
'eleman iþaretli mi?
If ChkBoxListFonklar.Items(i).Selected Then
'sorguya ekle(burayý yazýnca bitecek)
If Len(sorguRoleID) = 0 Then
sorguRoleID = "IDKARSILASTIR.[FONKSIYONID] = " & CStr(ChkBoxListFonklar.Items(i).Value)
'sorguRoleID = "ROLE.[ROLEADI] = " & CStr(ChkBoxListFonklar.Items(i).Text)
Else
DrpDwnFonkRole.DataTextField = ""
sorguRoleID = sorguRoleID & " OR IDKARSILASTIR.[FONKSIYONID]= " & CStr(ChkBoxListFonklar.Items(i).Value)
'sorguRoleID = sorguRoleID & " AND ROLE.[ROLEADI]= " & CStr(ChkBoxListFonklar.Items(i).Text)
End If
End If
Next
sorguKisim2 = ")"
'******************************************************************
Dim oleAdap As New OleDbDataAdapter(sorguKisim1 & sorguRoleID & sorguKisim2, objConn)
Dim ds As New DataSet
oleAdap.Fill(ds, "ROLE")
DrpDwnFonkRole.DataSource = ds
DrpDwnFonkRole.DataTextField = "ROLEADI"
DrpDwnFonkRole.DataBind()
DrpDwnFonkRole.Visible = True
objConn.Close()

Catch
objConn.Close()
End Try

sal
Starting Member

6 Posts

Posted - 2006-02-24 : 12:38:05
Not sure I can make sense of what the SQL is. Never seen it constructed that way. Can you post what it is before the code runs?
As an aside, your try block is not good. Not an error, maybe, but not good. You don't need to put Dim statements in them, and your objConn.Close should be in a Finally block. When you Catch an exception, you should do something with it, even if it's just displaying the error in a messagebox.
Go to Top of Page
   

- Advertisement -