|
In the link on your post , I red that this can be applied on Entity Framework with Code First.
I'm using Database First ???
|
|
|
|
|
Does your context class inherit from DbContext or ObjectContext ? If it's DbContext , then the code I posted should work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Public Function isAdministrator(AdminLevelID As Integer) As Boolean
Dim DBComm As DbCommand
Dim strsql As String = ""
strsql = "SELECT IsAdministrator FROM tb_GE_AdminLevel WHERE SysID =" & AdminLevelID
Return (DBComm.ExecuteScalar(strsql))
End Function
Public Function GetAllAdminMenu(ByVal AdminLevelID As Integer, Optional ByVal CustomerID As Integer = 0) As DataTable
Dim dt As New DataTable
Dim dbcommSave As DbCommand
Dim strSql As String = ""
Try
If (isAdministrator(AdminLevelID)) Then
strSql = "SELECT AdminMenuID,AdminMenuName,ParentID,IsNull((Select 1 As Allow from [tb_GE_AdminLevelMenu] Where AdminMenuID = A.AdminMenuID AND SysID = " & AdminLevelID & " ),0) As checked FROM tb_GE_AdminMenu As A ORDER BY SrNo"
Else
strSql = "SELECT AdminMenuID,AdminMenuName,ParentID,IsNull((Select 1 As Allow from [tb_GE_AdminLevelMenu] Where AdminMenuID = A.AdminMenuID AND SysID=1),0) As checked FROM tb_GE_AdminMenu As A ORDER BY SrNo"
End If
''strSql = "SELECT MenuID,MenuName,ParentID FROM tb_GE_Menu ORDER BY SrNo"
dbcommSave = Db.GetSqlStringCommand(strSql)
dt.Load(Db.ExecuteReader(dbcommSave))
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "SQL Exception")
End Try
Return dt
End Function
|
|
|
|
|
You can't solve what? You have not asked a question.
Say what problem you are having, any error messages etc, and what you are trying to do, as we are not telepathic
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Sorry
The "isAdministrator" returned null value!
|
|
|
|
|
|
Solve what? You haven't said what the problem is. We can't read your mind or see your screen so you have to explain it to us.
|
|
|
|
|
Okay, Fine!
I'm sorry!
|
|
|
|
|
Your code is vulnerable to SQL Injection[^].
NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Can I use WM_CTLCOLORSCROLLBAR for changing VSFlex Grid's Scroll Bar?
Please kindly give me some advice?
|
|
|
|
|
when some one changes the status: as 'Getting Daily Feed' in addition to saving the status as of now we need to call following URL is '(http://dev.bullseyeprospecting.com/api/dealer/saveevent?dealerGuid=&eventCode=A&userid=5212404' .
How can i do this in wcf .
|
|
|
|
|
Yeah, that made no sense at all.
We have no context information, nothing about your application, the details of exactly what you're trying to accomplish, what the problem is, ... nothing.
|
|
|
|
|
I have a dropdown name PER-PS 101 report. When I click view report it supposed to show the report if have values and "No records found for the selected criteria" if no data between the selected date. But in my case, if there is no data, its showing missing parameter error.
Below is the code:
Private Function ShowICDReport101() As Boolean
Try
Dim MessageString As String
Const ReportName As String = "ICD_InpatientReturn_Main.rpt"
Dim ReportDocumentObject As New ReportDocument
Dim ReportParametersListObject As List(Of ReportParameters)
Dim CrystalReportHelperObject As New CrystalReportHelper
'Dim ds As New DataSet
Dim ReportFilePath As String
ReportFilePath = CrystalReportHelperObject.DeploymentPath("CrystalReportsFilePath") + ReportName
ReportParametersListObject = SetReportParameters()
'To call the CheckReportData() function
If CheckReportData(ParentFormController.DateByMonthDateTimePicker.Value.Month.ToString(), ParentFormController.ToYearDateTimePicker.Value.Year.ToString(), ApplicationHelper.UserId) = True Then
ReportDocumentObject = CrystalReportHelperObject.GetCrystalReportDocument(ReportName, ReportParametersListObject)
If ReportDocumentObject.HasRecords = True Then
ParentFormController.ShowCrystalReportInViewer(ReportDocumentObject, "ICD Healthcare Facilities for Inpatien Returns", False, String.Empty)
Else
MessageBox.Show(MessageString, "Care21", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
Else
MessageString = "No records found for the selected criteria"
MessageBox.Show(MessageString, "Care21", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
Catch ex As Exception
Throw
End Try
End Function
Public Function CheckReportData(ByVal Month, ByVal Year, ByVal Userid) As Boolean
Dim ReturnCode As Boolean = False
Dim ReturnValues As New Dictionary(Of String, Object)
Dim result As Boolean
Try
Dim DbObject As Microsoft.Practices.EnterpriseLibrary.Data.Database = DatabaseFactory.CreateDatabase()
Dim DbCommand As DbCommand = DbObject.GetStoredProcCommand("usp_Rpt_InpatientReturns")
Data.AddInParameter(DbCommand, "@paMonthIn", DbType.String, Month, DbObject)
Data.AddInParameter(DbCommand, "@paYearIn", DbType.String, Year, DbObject)
Data.AddInParameter(DbCommand, "@paUserIdIn", DbType.String, Userid, DbObject)
Dim dt As DataTable
Dim ds As New DataSet("tt")
Dim DataReaderObject As IDataReader = DbObject.ExecuteReader(DbCommand)
dt.Load(DataReaderObject) 'If DataReaderObject.FieldCount = 0 Then
'Else
'End If
If dt.Rows.Count = 0 Then
result = False
Else
result = True
End If
DbCommand.Parameters.Clear()
'If ReturnValues("Result").ToString().Equals("1") Then
'Return True
'Else
' Return False
'End If
Catch ex As Exception
Throw
End Try
Return result
End Function
|
|
|
|
|
Running from your message that is displayed. I am assuming that this is the if check that is run before the message is displayed.
Member 11727014 wrote: If CheckReportData(ParentFormController.DateByMonthDateTimePicker.Value.Month.ToString(), ParentFormController.ToYearDateTimePicker.Value.Year.ToString(), ApplicationHelper.UserId) = True Then
Have you checked to see what the values that these parameters have before the function is run? Also what is ParentFormController.DateByMonthDateTimePicker and ParentFormController.ToYearDateTimePicker.Value.Year.ToString() ? are these controls?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Check your underlying data set, retrieved using usp_Rpt_InpatientReturns - sometimes a misspelled column name will generate an invalid parameter message
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
i'm using Visual Basic 2010 with database of Microsoft Access 2007 . how can i print the data in datagridview? (the column was 10 and the row was many because they always add a new data )thank you
|
|
|
|
|
|
Hello !
I have an application in vb.net 2013 and sql server 2008r2 and Entity Framework 6.0.
I'm trying to implement a "Event Log" feature in my application.
Actually :
I have an Event table in database that will keep all the activities (with details) that a user has done in this database from my application.
The only problem I have is this :
One of the field in the Event table is ObjectID , that is supposed to keep the id of the record that is related with that event.
But the problem is that how this Event will going to be read.
Because for example :
Event1 ... may be related with Clients table , with a record with ID=25
Event2 ... may be related with Articles tables , with a record with id 40
......
In this case , I can't use a foreign key with the field ObjectID because it need to be flexible ( related with different tables ) and I don't know if this is possible.
But also , if I keep only the id , and add another field that keep the table name , how can I read with entity framework ?
Any suggestion will be very helpful.
Thank you !
|
|
|
|
|
satc wrote: In this case , I can't use a foreign key with the field ObjectID because it need
to be flexible ( related with different tables ) and I don't know if this is
possible. I'd recommend looking into 'normalization', a modelling technique for databases that helps a lot in these cases.
Add the table-name a a field to the event-table; the Id and tablename together would make each record unique. Since you don't want to repeat the table-name for each record, I'd suggest putting the table-name as a KeyPairValue (int/varchar) and link to that from the event-table.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy, I noticed you overlooked this part of his question - do you have a suggestion for that? (I don't)
Quote: But also , if I keep only the id , and add another field that keep the table name , how can I read with entity framework ? (Presumably as in "read the referenced record though it's not referenced by a foreign key")
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I don't see why it wouldn't be able to read it back.
In the worst case scenarion one would open an SqlConnection outside of EF, connect, read the id and tablename - and build a new command.
There's offcource no way to use a fieldname in the place of a table-name.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
SqlConnection outside EF - check.
But how could the non-worst case look like? (Maybe I'm having a stupid moment..)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefèvre wrote: But how could the non-worst case look like? I don't have experience with EF; in the best case it would pick up the new column-name in the database, update the model and generate new entities. That would making reading the table easier for someone who is used to EF. To me, it is merely a select-statement.
The main problem here is getting the table-name (data) back into the sql-command. That is not something that can be done in Sql (unless you go to, spit, dynamic sql) and should be done in the codelayer above.
Make a new command, say "I need from table x the Id y" and of you are.
Sascha Lefèvre wrote: (Maybe I'm having a stupid moment..) Noes, you're not. I'm a bit more confused than usual, having trouble concentrating. Doesn't mean I'm not going to try
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Alright
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The problem is that as I know , the entity framework doesn't have a way to read where the entity name is variable :
Dim Ename as string
......
......
Dim query=From t in context.[Ename]..... select t
Can this work ?
|
|
|
|