I'm having a challenge with the following string:
Datedeath: IIf([Members.Status]=[“DA”] Or [“DB”] Or [“DJ”] Or [“DC”], else [members.deathdate] "29/02/1844"
Might someone be able to guide me as to how to write this iif statement please?
Check if the condition fulfilled, set new date or leave it
[members.deathdate]:IIf ((([Members.Status] = "DA" Or [Members.Status] = "DB" Or [Members.Status] = "DJ" Or [Members.Status] = "DC") And ([members.deathdate] = "" Or IsNull([members.deathdate]))), "29/02/1844", [members.deathdate])
Related
I am building a MySql query in vb.net:
cmd.CommandText = "Select id INTO #idDep from dBase.tableA where guid in (#strdepToDelete, #strOtherToDelete) and IsDependent = '1'; " & _
"Select id INTO #idOther from dBase.tableA where guid in (#strdepToDelete, #strOtherToDelete) and IsDependent = '0'; " & _
"delete from dBase.tableA where id in(#idDep, #idOther);"
cmd.Parameters.Add("#strdepToDelete", MySql.Data.MySqlClient.MySqlDbType.String)
cmd.Parameters("#strdepToDelete").Value = strdepToDelete
cmd.Parameters.Add("#strOtherToDelete", MySql.Data.MySqlClient.MySqlDbType.String)
cmd.Parameters("#strdepToDelete").Value = strOtherToDelete
cmd.Parameters.Add("#IdDep", MySql.Data.MySqlClient.MySqlDbType.Int24)
cmd.Parameters("#IdDep").Value = Nothing
cmd.Parameters.Add("#IdOther", MySql.Data.MySqlClient.MySqlDbType.Int24)
cmd.Parameters("#IdOther").Value = Nothing
Try
cmd.ExecuteNonQuery()
success = True
Catch ex As Exception
End Try
Return success
Error is caught which indicates that Null cannnot be #IdDep value. I have tried "" for value of that variable; I have tried ? for value of that variable. When I run the command text gained from hovering over cmd in MySql it works as it should. My question is how to paramaterize queries with nothing value.
I don't think your problem is the datatype, the command object is pretty good at inferring DBNull from Nothing. I think your SQL statement is the problem...
If you have an IN statement, FldNm IN(1,2,NULL) then the SQL engine will parse it as FldNm=1 OR FldNm=2 OR FldNm=NULL. That last item isn't valid (for SQL in general, and also for MySQL in particular ... just tried it to make verify).
You can ask for records where FldNm IS NULL, but not where FldNm=NULL.
So - when you construct that SQL statement, you'll need to skip the values in your IN clause if they are null. OR - use some non-existent value if the value is null as a "work around."
Hope that's helpful!
Please help with my task.
I need to extract data from database and pack it in collection of object.
I try this code
DataClasses1DataCotext db = new DataClesses1DataContext();
IEnumerable<SimpleSMS> newSmses = db.SimpleSMS.GetEnumerator();
.....
but I haven't idea how to add filter (where db.SimpleSMS.Status = null)
Try the LINQ query:
IEnumerable<SimpleSMS> newSmses = (from pld in db.SimpleSMS
where pld.Status == null
select pld).GetEnumerator();
I hope it will help you.. :)
IEnumerable<SimpleSMS> newSmses = db.SimpleSMS.Where(s => s.Status == null).AsEnumerable();
I have a query in microsoft Access that accepts few parameters. I'm looking for an example in C# that will let me be able to "Derive" parameters from the query first before populating them with values.
Can this be done? Please tell me how asap.
There are many questions like this in in other sites in the web but with no answer.
The only way I can see of doing this is with DAO, but there may be others.
DBEngine dbEng = new DBEngine();
Workspace Ws = dbEng.CreateWorkspace("", "admin", "", WorkspaceTypeEnum.dbUseJet);
Database Db = Ws.OpenDatabase(#"Z:\Docs\Test.accdb", false, false, "");
QueryDef qry = Db.QueryDefs["MyStoredQuery"];
foreach (Parameter prm in qry.Parameters)
{
Console.WriteLine(prm.Name);
Console.WriteLine(prm.Type);
}
The only way you will get an accurate type is if you include a Parameter statement :
PARAMETERS param1 Text ( 255 ), param2 Integer;
I have added a table(ViolationsDataSourceConfig) to the dbml file.
The context name is ViolationsDataContext.
I am trying to write a function that should return employee object but it is throwing errors. Below is the code. Is there any easy way for achieving this. I just want the ViolationsDataSourceConfig.
Public Shared Function GetDataSourceDetails(ByVal ApplicationID As Integer) As ViolationsDataSourceConfig
Dim _db As New ViolationsDataContext
Dim appSource As New ViolationsDataSourceConfig
Dim application As Table(Of ViolationsDataSourceConfig) = _db.GetTable(Of ViolationsDataSourceConfig)()
Try
appSource = From a In application Where a.ApplicationID = ApplicationID And a.Status = 1 _
Select a
Catch ex As Exception
End Try
Return appSource
End Function
It's a little hard without more information regarding your data structures or the errors you're getting, could you provide the error at least?
Also, you say your LINQ statement should "return employee" but you are typing it as "ViolationsDataSourceConfig", how does that work?
My first thought would be the LINQ statement will return an IEnumerable by default so it probably won't be the correct type.
ppSource = (From a In application Where a.ApplicationID = ApplicationID And a.Status = 1 _
Select a).FirstOrDefault()
Might be closer to your goal...
I need to update my exist data in mysql database.
I write like this code;
String _id = lbID.Text;
dsrm_usersTableAdapters.rm_usersTableAdapter _t = new dsrm_usersTableAdapters.rm_usersTableAdapter();
dsrm_users _mds = new dsrm_users();
_mds.EnforceConstraints = false;
dsrm_users.rm_usersDataTable _m = _mds.rm_users;
_t.FillBy4(_m, _id);
if(_m.Rows.Count >0 )
{
DataRow _row = _m.Rows[0];
_row.BeginEdit();
_row["username"] = txtUserName.Text;
_row.EndEdit();
_row.AcceptChanges();
_t.Update(_m);
}
But nothing change my exists data. What is the Problem?
I think the problem is that you call DataRow.AcceptChanges() before calling DbDataAdapter.Update(). AcceptChanges will set the status of the datarow to "orignal" (or "not changed" - I don't remeber now). Try to move the call to AcceptChanges to after the Update.
Update requires a valid UpdateCommand when passed DataRow collection with modified rows
Yes I move the AccesptChange() after update bu now its give this error
Update requires a valid UpdateCommand when passed DataRow collection with modified rows
But now problem is, I use MySQL and I can not Wrie UpdateCommand , VS2008 does not accept the SQL command. Automaticly delete all SQL command. I dont understand the problem. So do you now another way without using SQL command (UpdateCommand) ?