|
Luc, you are on my Christmas list. Thank you! Your first reply worked perfectly, and gave me exactly the results I needed! 
|
|
|
|
|
How do you check to see if the string collection is null first? Now my program is crashing because of that.
|
|
|
|
|
|
string authors = string.Join(", ", md.Author ?? new string[] { "<nn>" });
That didn't work.
Operator '??" cannot be applied to operands of type 'ReadOnlyCollection<string>; and 'string[]'
Thank you.
|
|
|
|
|
Use simple statements:
if (md.Author != null)
{
string[] authors = md.Author;
}
else
{
}
|
|
|
|
|
Try:
string authors = string.Join(", ", md.Author.AsEnumerable() ?? Array.Empty<string>());
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Good afternoon,
I am adding a spot to create the initial Access DB for my program and I am able to get the tables & columns created just fine.
I have one column that has program specific information, (ex: paydays (weekly, 2x month, bi monthly, monthly, etc.)
Where can I find information as to how to load that specific information from a list or something into that one specific column? There are 5 or 6 items.
Richard
Disable Vet
Grandfather
Pain in the @ss
|
|
|
|
|
The best idea is not to: create a second table that contains each of the various options and has two columns: an ID (can be integer) and a description.
Then your main table contains ID values which are a foreign key to the new table.
That way, you can only hold valid values, and people don't add new ones by mistake by mistyping, or adding punctuation, or the wrong case.
Access is a relational database, and relations between tables are one of the things it is good at: See SQL JOINs for more info: SQL Joins[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I agree with @OriginalGriff but over 20 years ago I had a requirement to do what you wanted (I forget the details now), probably for a report or some such. The code that I used was ...
(This code was run in-stream as a column inside the query in MS-Access, not as 'external' C# accessing an Ms-Access table)
Function MakeList( _
ByVal InSQL As String, _
Optional ByVal InColName = 0, _
Optional ByVal InSeparator As String = ",", _
Optional ByVal InDataBase = "" _
) As String
Dim DB As Database
Dim rs
If IsObject(InDataBase) Then
Set DB = InDataBase
Else
Set DB = IIf(InDataBase = "", CurrentDb, OpenDatabase(InDataBase))
End If
Set rs = DB.OpenRecordset(InSQL)
While Not rs.EOF
MakeList = MakeList & InSeparator & rs(InColName)
rs.MoveNext
Wend
rs.Close
DB.Close
MakeList = Mid(MakeList, Len(InSeparator) + 1)
End Function
|
|
|
|
|
I have a asp view.
I need to pass a field to the .cs method
I have a : < form...> with a post method.
This is the field on the .chtml i need to read:
<input type="text" name="username" id="username" class="form-control ewControl" value="@_login.Username" placeholder="@Language.Phrase("Username")" autocomplete="username">
Using this:
<a href= 'login?expire=1' class="btn btn-ic btn-link pkg-photo">Olvide mi clave</a>
the data it is lost when i try to used it on the .cs
Any want can help me?
|
|
|
|
|
An <a> element will navigate to the URL specified by its href attribute. It will not submit the form.
If you want to submit the form instead, use a <button type="submit"></button> or an <input type="submit"/> .
If you want the data to be sent to a different URL than the form's action , use the formaction attribute[^] on the button.
<button type="submit" formaction="login?expire=1" class="btn btn-ic btn-link pkg-photo">Olvide mi clave</button>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The idea just crossed my mind to make my data structure on my home project thread safe.
luckily there is a common entry point where I can Monitor.Enter() and Monitor.Exit() (the UndoManager).
But I wonder.. is it worth it?
I.e. will I trade useless (so far) thread safety at the cost of worsening performance?
although, come to think of it... I might still have some read corruption, even if I lock the write operations... mmm...
[EDIT]
Mmm... just stumbled on it, is SpinLock the performance friendly version of Monitor?
modified 2-Dec-21 21:38pm.
|
|
|
|
|
There is also ReaderWriterLock(Slim) to deal with that issue of synchronizing writes, and avoiding read-write-collisions, but letting multiple reads be done simultaneously. Another technique is Read Copy Update, in that case readers do not need to take any lock, but updating can be more expensive, and readers may use out-of-date data for a little while.
But obviously, if you don't need it, don't add it. Uncontended locks aren't that bad, but still not free, and in any case you'd be writing useless code..
|
|
|
|
|
Thanks man.. I might just skip it...
I was influenced by work where they need thread safety on the data structure, I thought it would be could if mine has that too. But as you pointed, counter productive if I don't need thread safety...
|
|
|
|
|
Super Lloyd wrote: luckily there is a common entry point That makes it easy, but ... If the traffic is high, so there is a definite risk that one or more (or many!) tasks may be queued in line for access to the resource, and the resource is a large structure, you may be preventing access to far more than you need to. Maybe others could safely access most of the structure when you are working on another part of it.
Compare it to locking in database systems: The oldest systems locked the entire table, no other transaction could affect any part of it. A banking system with twelve tellers was as slow as one with a single teller, because they all had to wait for the table to be released. The next development step was to lock individual tuples, so as long as the tellers were referring to different accounts, they could proceed.
One main justification for B-link trees (over other B-tree-variants) is that even when a block is split, you need only lock a single block at a time; other threads may freely access all other blocks in parallel.
If you have had no protection until now, there probably isn't that much congestion, and this is not too much of a concern. Yet, as a general rule: It is a good idea to lock only the data that you really are using!
|
|
|
|
|
Is it worth it?
Isn't that essentially a question of addressability? How many threads exist that can address the data structure at all? And do it at the same time?
I have written web servers handling one request at a time - the processing time, and traffic load, was so low that there was no reason to take the complexities of a multi-threaded server. So only a single thread was accessing the data structure, with no need to protect it.
You may have multiple threads in your code, but the other threads do other tasks; only one is accessing this structure, you are not publishing entry points or pointers to it to any other software, and if you run two instances of your code, they have individual copies of the structure? Then, no need to protect it.
You may have one startup thread building the structure, and later another working thread using it - but the first thread has completed before the second has started: They are not addressing the structure at the same time. No need to protect it.
But if there are two or more threads that may address the structure, it may happen at the same time, and a least one of these threads make modifications to the structure: Yes, then it is worth it. Especially when the implementation is as simple as you indicate, but that really shouldn't be any argument: You should protect your data from inconsistencies even if the implementation effort is above epsilon.
Runtime costs: How frequently is this data structure entered? Several times every millisecond, 24/7? Less than that? Then you can spend the time! Modern implementations of sync primitives are highly tuned code, and modern processors provide instructions to make it fast and efficient. Set up a timing loop to enter and exit your structure a million times, with and without the protection. You'd probably be surprised by how little the sync primitives add to the timing results.
Add a counter that is incremented every time you enter the structure structure, and do a few runs. If you see that the structure is entered millions of times, so the sync operations would take measurable time, then reconsider your code: Maybe you could enter the monitor to do a dozen individual operations before leaving, rather than entering and leaving a dozen times, once for each individual operation.
Admittedly, this breaks the first law of optimization: Don't do it! Depending on the state of your project, it may even break the second law of optimization: If you have to do it, don't do it yet!
Protecting data structure integrity is the other way around: If you don't have to do it, do it anyway. And: If you haven't yet done it, do it now, from the beginning!
If there is a risk of conflict, it is worth it!
|
|
|
|
|
Good morning,
I am self-teaching myself and I am trying to find a tutorial, examples, direction on how to update a combobox collection of items in Form 1, after I do an insert into the database from Form 2. I am using Access database because thats what I understand, have available to me and I dont want to try learn multiple software packages at the same time.
I have Visual Studio 2019.
I was creating a bill management program for me and from the creditors menu (Form1), which just lists all the creditors names in a combobox, an exit, a new bill and edit buttons, I select the new bill button and it takes me to creditorEditor (form2) and it is there where I add a new bill. Upon clicking the save button, it adds the information to the original database, closes Form 2 and shows form 1 once more. Upon returning to Form 1, I want to be able to click on the combo box and see the new addition of the creditors name, without having to exit out one menu level then returning.
I am not sure I am asking this correctly, if not please tell me what I should be providing for information.
Richard
Disable Vet
Grandfather
Pain in the @ss
|
|
|
|
|
A key piece of information: what happens when you select one of the creditor names in the ComboBox in Form1 ? Does tha open up Form2 again, and display the creditor information and/or allow editing it ?
Getting the new creditor name back to Form1 is easy:
Form2 f2 = new Form2();
f2.AddCreditorName += UpdateComboBox;
public void UpdateComboBox(string newCreditorName)
{
comboBox1.Items.Add(newCreditorName);
}
public Action<string> AddCreditorName = null;
if (AddCreditorName != null) AddCreditorName(CreditorNamtmeTextBox.Text);
Notes:
1) consider hiding/showing the instance of Form2, rather than creating/closing a new instance of Form2 ... of course that may mean you'll need to write some code in Form2 to clear all the entry fields.
2) the act of injecting executable code (the delegate instance aka 'handler) into an instance of Form2 ensures "separation of concerns:" it prevents dependencies between forms causing unexpected side-effects.
3) imho, it is best practice to validate user entered data in the execution context in which it occurs (instance of Form2, here), and to not allow users to make choices that will lead to errors. An example: disable the 'Save button until validation is complete, but, of course, leave a 'Cancel button enabled.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Thank you for response.
What I ended up going with is as follow:
What I did was separate out the loading of the creditor information into its own operation. It used to be under the CreditEditor_Load, now I just call the operation there and then I am also able to call that same operation from an event handler.
Not sure this is necessarily the best way, but it seems to work exactly as I want.
What do you think?
Richard
void CreditorDataLoad()
{
try
{
cbo_BillName.Items.Clear();
string query = "select C_Name From Creditor";
AC.cmd.Parameters.Clear();
AC.cmd.CommandType = CommandType.Text;
AC.cmd.CommandText = query;
AC.openConnection();
AC.rd = AC.cmd.ExecuteReader();
if (AC.rd.HasRows)
{
while (AC.rd.Read())
{
cbo_BillName.Items.Add(AC.rd[0].ToString());
}
}
AC.rd.Close();
AC.closeConnection();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
private void btnNewBill_Click(object sender, EventArgs e)
{
billName = null;
this.Hide();
creditEditor f2 = new creditEditor(this);
f2.FormClosed += new FormClosedEventHandler(creditEditor_FormClosed);
f2.ShowDialog();
}
void creditEditor_FormClosed(object sender, EventArgs e)
{
CreditorDataLoad();
}
|
|
|
|
|
If a user "kills" an app, form closed does not get called; in case you were counting on it to "save" your data.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hello everybody,
I have to modify this code (the programmer who did it is not longer with us)
The problem is:
If you type the userid and password and click LOGIN: the program take the userid and password
but if you FORGOT your password, and click: Forgot password(Olvide contrasena), the programa check if you did not type the userid and show you a warning, the problem is that if you type the userid, and click Forgot the password, the userid it is not reads on the program. Any help?
The .chtml
<div class="box box-primary login-box ewLoginBox">
<div class="login-box-body">
<p class="login-box-msg">@Html.Raw(Language.Phrase("Login"))</p>
<div class="form-group">
<div>
<input type="text" name="username" id="username" class="form-control ewControl"
value="@_login.Username" placeholder="@Language.Phrase("Username")" autocomplete="username">
</div>
</div>
<div class="form-group">
<div><input type="password" name="password" id="password" class="form-control ewControl"
placeholder="@Language.Phrase("Password")" autocomplete="current-password"></div>
</div>
<div class="checkbox">
<label for="rememberme"><input type="checkbox" name="type" id="rememberme" value="a"
@Html.Raw((_login.LoginType == "a") ? " checked" : "")>@Html.Raw(Language.Phrase("RememberMe"))
</label>
</div>
<button class="btn btn-primary btn-block ewButton" name="btnsubmit" id="btnsubmit"
type="submit">@Html.Raw(Language.Phrase("Login"))
</button>
@if (Config.Authentications.Count(kvp => kvp.Value.Enabled) > 0)
{
<div class="social-auth-links text-center">
<p>@Html.Raw(Language.Phrase("LoginOr"))</p>
@foreach (var kvp in Config.Authentications.Where(kvp => kvp.Value.Enabled))
{
<a href="ExternalLogin?provider=@kvp.Key" class="btn btn-block btn-social btn-flat btn-
@kvp.Key.ToLower()">class="fa fa-@kvp.Key.ToLower()">@Html.Raw(Language.Phrase("Login"
+ kvp.Key))</a>
}
</div>
}
<a href= 'login?expire="@_login.Username"' class="btn btn-ic btn-link pkg-photo">Olvide mi clave</a>
</div>
</div>
The .cs is:
public IActionResult Page_Main() {
Username = ""; // Initialize
string password = "";
string lastUrl = Security.LastUrl; // Get last URL
if (Empty(lastUrl))
lastUrl = "Index";
// Login
if (IsLoggingIn()) { // After changing password
{
Username = Session.GetString(Config.SessionUserProfileUserName);
password = Session.GetString(Config.SessionUserProfilePassword);
} else { // Normal login
if (!Security.IsLoggedIn)
Security.AutoLogin();
Security.LoadUserLevel(); // Load user level
bool encrypted = false;
if (!Empty(Post("username"))) {
// Login by form post
Username = RemoveXss(Post("username"));
//Here the error, we sent 1, which it is passed, but the username is lost even you type, so the if (!Empty(Post(Username))) it is never executed
if (Get<bool>("expire"))
{
if (!Empty(Post(Username)))
{
|
|
|
|
|
First use the browser's development tool to check the data going from the browser to the backend - does it contain the username in the format you expect - if not, doublecheck the generated html (again, the browser will let you examine this). If the username is included, you need to debug the server side. It seems it wants to read the username from the season - so put a breakpoint ok n the code putting the username in the session in the first place... Does it even execute?
|
|
|
|
|
I'm creating a program for my school and I have the majority of the bugs fixed but I'm stuck on one part that I can seem to get the timer to stay active after the program is closed. This program allows the user to enter mins and seconds for a timer so they can complete tasks in time but each time the program is closed the timer resets to 0. Is there a way I can make it so maybe when they close the software it doesn't really close it but minimizes it so the timer can continue to run?
|
|
|
|
|
It depends on what you are actually trying to do with your timer: you can't set up a timer within your application and have it run after the app is closed, so it you are doing this to "time" an exam or similar, then it's totally the wrong approach as it's very simple to bypass - bring up task manager and terminate the app process.
So you need to think about exactly what you are trying to use the timer for: what purpose does it serve? What should happen when it expires? What if the use logs out? Turns off the computer? Runs two copies of the app?
There are ways - pretty simple ones - to say "this task must be completed by hh:mm today" and persist that between runs of the app, but that may not be appropriate, depending on your use case.
Similarly, there are ways to minimize the app when it's told to close - but those are nothing like infalible so again, it depends on your use case if that is appropriate.
And we have no idea what you are trying to do with this - we have no access to your system, and only get exactly what you type to work with!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Before we can answer your question, you really need to tell us what type of application this is. Is it a console application? A WPF application? WinForms? WinUI?
|
|
|
|
|