30-04-17, 06:25 PM
كود قواعد بيانات الكود ده vb.net وعايزو يشتغل على ال #c
كود :
Sub LoadCategory()
Try
sqlstr = "Select Id,VideoCategory From tblCategory"
da = New OleDbDataAdapter(sqlstr, con)
ds = New DataSet
'
ds.Clear()
da.Fill(ds, "tblCategory")
'
ComboBox1.Items.Clear()
ComboBox1.DataSource = ds.Tables("tblCategory")
ComboBox1.ValueMember = "id"
ComboBox1.DisplayMember = "VideoCategory"
Catch ex As Exception
If ex.Message.ToString.ToLower.Contains("cannot open database it may not be a database that your application recognizes") Then
MsgBox("حدثت مشكلة فى البرنامج و جارى تحميل ملف حل المشكلة الرجاء تيطيبة بعد اكتمال التحميل و عدم غلق البرنامج الا مع اكتمال التحميل", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "خطأ")
My.Computer.Network.DownloadFile("https://download.microsoft.com/download/2/4/3/24375141-E08D-4803-AB0E-10F2E3A07AAA/AccessDatabaseEngine.exe", Application.StartupPath & "\AccessDatabaseEngine.exe")
'كدة هيحمل الملف اللى هيصلح الرسالة التانية جنب البرنامج
IO.File.Open(Application.StartupPath & "\AccessDatabaseEngine.exe", IO.FileMode.Open)
ElseIf ex.Message.ToString.ToLower.Contains("the microsoft.ace.oledb.12.0 provider is not registered on the local machine")
MsgBox("حدثت مشكلة فى البرنامج و جارى تحميل ملف حل المشكلة الرجاء تيطيبة بعد اكتمال التحميل و عدم غلق البرنامج الا مع اكتمال التحميل", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "خطأ")
My.Computer.Network.DownloadFile("https://download.microsoft.com/download/2/4/3/24375141-E08D-4803-AB0E-10F2E3A07AAA/AccessDatabaseEngine.exe", Application.StartupPath & "\AccessDatabaseEngine.exe")
IO.File.Open(Application.StartupPath & "\AccessDatabaseEngine.exe", IO.FileMode.Open)
End If
End Try
End Sub
Sub LoadVideoName(ByVal Value As Integer)
Try
sqlstr = "Select Id,VideoName From tblVideo Where CategoryId = @CategoryId"
da = New OleDbDataAdapter(sqlstr, con)
'
da.SelectCommand.Parameters.Add(New OleDbParameter("@CategoryId", Value))
'
If ds.Tables.Contains("tblVideo") Then
ds.Tables("tblVideo").Clear()
End If
'
da.Fill(ds, "tblVideo")
'
ComboBox2.DataSource = ds.Tables("tblVideo")
ComboBox2.ValueMember = "id"
ComboBox2.DisplayMember = "VideoName"
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub LoadSubVideo(ByVal Value As Integer)
Try
sqlstr = "Select Id,SubVideo,LinkVideo From tblSubVideo Where VideoId = @VideoId"
da = New OleDbDataAdapter(sqlstr, con)
da.SelectCommand.Parameters.Add(New OleDbParameter("@VideoId", Value))
'
If ds.Tables.Contains("tblSubVideo") Then
ds.Tables("tblSubVideo").Clear()
End If
'
da.Fill(ds, "tblSubVideo")
'
ListBox1.DataSource = ds.Tables("tblSubVideo")
ListBox1.ValueMember = "LinkVideo"
ListBox1.DisplayMember = "SubVideo"
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub