|
Please help. How to put two columns in a combo box (list Box, text box:mad. I work with VS2015, c# and MySql 5.7.
Attached part of the code.
private void comboBox1_Click (object sender, EventArgs e)
{
MySqlConnection conn;
myConnectionString = pwput;
conn = new MySql.Data.MySqlClient.MySqlConnection ();
conn.ConnectionString = myConnectionString;
try
{
conn.Open ();
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER, CLOSE PROGRAM TO TAKE A REPLY");
Close ();
break;
case 1042:
MessageBox.Show ("NOT ACTIVE SERVER, SUBSCRIBE SERVER PA REPEAT CONNECTING");
Close ();
break;
}
conn.Close ();
}
if (conn.State! = ConnectionState.Open)
{
MessageBox.Show ("DO NOT SUCCE TO CONNECT ON SERVER \ r \ n CLOSE PROGRAM TO TAKE READY \ r \ n");
}
else
{
AutoCompleteStringCollection kontoopis = new AutoCompleteStringCollection ();
string wnadidok = "SELECT idkonto, FROM account name";
loadingData = false;
DataTable dtkon = new DataTable ();
dtkon.Columns.Add ();
dtkon.Columns.Add ();
MySqlDataAdapter mdkon = new MySqlDataAdapter (wnadidok, conn);
mdkon.Fill (dtkon);
loadingData = true;
comboBox1.DataSource = dtkon;
// which field is shown in the table below
comboBox1.DisplayMember = "idkonto";
comboBox1.ValueMember = "idkonto";
comboBox1.DisplayMember = "title";
comboBox1.ValueMember = "title";
comboBox1.SelectedIndex = -1;
comboBox1.Text = "";
loadingData = false;
}
conn.Close ();
}
Thank you
|
|
|
|
|
|
|
your select query doesnt contans "title " but you have mapped the title to value member
the below lines repeating twice, however the compiler will takes only the latest assigned values
comboBox1.DisplayMember = "idkonto";
comboBox1.ValueMember = "idkonto";
comboBox1.DisplayMember = "title";
comboBox1.ValueMember = "title";
try concatenating the two columns in the select query as
string wnadidok = "SELECT idkonto + ' ' + title as combinedCol , title FROM [account name]";
and change the DisplayMember and ValueMember as
comboBox1.DisplayMember = "combinedCol";
comboBox1.ValueMember = "title";
|
|
|
|
|
|
welcome
|
|
|
|
|
I know very little about AD. I found this article but it's old.
We have a device that requires the user to log in. Currently, the usernames/passwords are stored in a table in the database on the device. In the table are also roles such as "Operator" and "Supervisor", and an Active checkbox.
We now have a requirement that if AD is configured/enabled, then use that to validate the user. This opens up some questions.
1) How can I tell in C# if AD is configured/enabled?
2) Is it possible using AD to store and retrieve the roles I mentioned as well as the Active checkbox?
The goal would be to not store this info locally on a device but to have validate and identify the user and device related information from outside the device.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It will probably be easier to use the System.DirectoryServices.AccountManagement[^] namespace. You can use Active Directory groups to represent the roles.
public static bool ValidateCredentials(string userName, string password)
{
using (var context = new PrincipalContext(ContextType.Domain))
{
return context.ValidateCredentials(userName, password);
}
}
public static bool IsUserActive(string userName)
{
using (var context = new PrincipalContext(ContextType.Domain))
{
var user = UserPrincipal.FindByIdentity(context, userName);
return user != null && user.Enabled == true;
}
}
public static bool IsUserInRole(string userName, string roleName)
{
using (var context = new PrincipalContext(ContextType.Domain))
{
var user = UserPrincipal.FindByIdentity(context, userName);
var group = GroupPrincipal.FindByIdentity(context, roleName);
return user != null && group != null && user.IsMemberOf(group);
}
}
To detect whether the computer is joined to a domain, you'll need to P/Invoke the NetGetJoinInformation[^] function:
.net - How to detect if machine is joined to domain (in C#)? - Stack Overflow[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
When you refer to Role, what exactly is that? Is a Role in the sense you're referring to something that can be defined by the System Admin?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Role is your concept, AD works with GROUPS and a user is a member of 1 or more groups, a heavy security requirement can be a nightmare. We had to get creative around the name of the groups to support department and role. Typically
Finance_Op = finance operations
Finance_RO = read only.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The article you describe as "old" has #337 votes. There's a comment with code suggestions in Oct, 2016, which the author acknowledged.
Is it too much to ask that you review more than one article on CP (out of many) ? [^]. Or that you visit StackOverFlow, and sample possibly relevant sources.
"If not you, who ? If not now, when ?" (sometimes attributed to Hillel the Elder)
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
BillWoodruff wrote: Is it too much to ask in this instance, probably.
|
|
|
|
|
I pointed out that it's old because AD has evolved over time. Some of the comments pointed out that there are newer ways of doing some of the things the article discussed.
BillWoodruff wrote: Is it too much to ask that you review more than one article on CP (out of many) ? [^]. Or that you visit StackOverFlow, and sample possibly relevant sources.
That's an assumption on your part that I haven't looked at other resources.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Having a AAA source like LDAP is how things should be done for any non-trival application with securables. It does a few things for you, such as de-obligating the engineer from concerns like identity and role tracking, and makes things grotesquely easier from an operations standpoint. If someone leaves the company, just disable 1 account rather than having to check each application and remove accounts.
While I respect Richard's advocacy of System.DirectoryServices.AccountManagement (S.DS.AM), I've played with the namespace some and, depending on the use case, have found it to be restrictive and slow. There are three namespaces for using AD in three different ways, and each has strengths and weaknesses. S.DS.AM is the newest library, and it has a number of helper functions out of the box and is streamlined a bit, but it interfaces with the MS ADSI interface, which is an entire operational layer that exists at a higher level than LDAP. The base namespace, System.DirectoryServices (S.DS) is less streamlined, but more flexible, but also leverages the ADSI interface.
I generally use System.DirectoryServices.Protocols (S.DS.P) since it doesn't touch ADSI and goes straight through as LDAP. The library is minimalist, so learning to use it can be tricky, but it is several orders of magnitude faster than the alternatives (and I mean hundreds), so if you find yourself working with multiple records it can be a life saver. It also de-couples you from Active Directory by targeting LDAP directly, which can be implemented in a few different ways.
Here's pretty comprehensive intro to S.DS.P if you're interested.:
Introduction to System.DirectoryServices.Protocols (S.DS.P)
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
..
modified 19-Nov-17 11:55am.
|
|
|
|
|
What "session code"?
What is it supposed to do?
When is it supposed to do it?
Remember: we know nothing about your project, and I for one am not going to wade through your whole project trying to to work what you haven't done!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi all,
I have a question.
I have to insert oracle table values in Access database.
I am storing oracle table values in datatable(dt).
In oracle and Access database "Net" field is a "Number"
Trying to insert "Net" field in access datatype i am getting following exception.
"Data type mismatch in criteria expression."
I have found out the reason is "Net" field value in oracle table is EMPTY ("").
What i did is trying to check the field IsNullOrEmpty, if it is Empty then i want to store null value into "Net" field(In Access database).
I have made some code change after that also receiving the same error message .
""Data type mismatch in criteria expression."
Please help me how to fix this.
What I have tried:
strNet = !string.IsNullOrEmpty(dr["NET"].ToString()) ? dr["NET"].ToString() : null;
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
sInsertValues= "'" + strNet + "'";
insertAEdetails.ParmValue = sInsertValues;
insertAEdetails.InsertIntoAccess();
iNbrInserts++;
}
}
|
|
|
|
|
Yuck. Create an Oracle "extract", fix that, and then import into Access.
Or use Access directly to access Oracle (link or import).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
sai.2012 wrote: sInsertValues= "'" + strNet + "'"; That turns everything into a string, and a string is not a number. Next, you'd want DBNull.Value, and not "null". Lastly, if a number-field in Oracle is empty, it is a DBNull, and not an empty string.
Fetch it as a number (Int32), save it as a number, and use command-parameters. That would also eliminate the redundant .ToStrings-calls.
Something like below;
Int32 someValue = Convert.ToInt32(dr["NET"]);
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
We have developed a .NET DLL using Visual studio 2015 targeted to .NET framework 4.0 .
We need to implement the licensing functionality for Design time and runtime .
Could you please suggest the best way to do that.
Note: This is just a .NET DLL NOT a component
|
|
|
|
|
|
I am new to using the "async" functionality in .NET. I have created a few GUI classes that are designed to give feedback to a user while time consuming tasks are completed. The core of this functionality is a "Task" class that makes use of the System.Threading.Tasks.Task class. It contains the "description" of the task being completed, the number of steps to be completed in the task, and the System.Threading.Tasks.Task task that is to be called within an async method. This "API task" that is the actual "task" to be performed amounts to calling a function within the class. The problem is that the creation of my "Task" action is causing a TargetInvocationException. I am getting the impression from the inner exception that the System.Threading.Task.Task is effectively a "null" task and I do not have the experience to understand why. Here is my code inside the async method:
async void OnGenerateMapData()
{
statusPanel = new StatusPanel();
statusPanel.AddTask(new Task("Processing Map Data", 1081 * 1081, true, new System.Threading.Tasks.Task(() => { ProcessPixelData(); })));
statusPanel.AddTask(new Task("Generating Shoreline", 1079 * 1079 + 50000, true, new System.Threading.Tasks.Task(() => { ProcessShoreline(); })));
statusPanel.AddTask(new Task("Updating Map", 1081 * 1081, true, new System.Threading.Tasks.Task(() => { UpdateResult(); })));
statusPanel.Dock = DockStyle.Fill;
this.Controls.Add(statusPanel);
Task currentTask = statusPanel.BeginTasks();
while (currentTask != null)
{
await currentTask.Action;
currentTask = statusPanel.AdvanceCurrentTask(0);
}
this.Controls.Remove(statusPanel);
statusPanel = null;
}
It may help to know that all the function calls being put into the "task" are within the same class as the async method. However, perhaps I need more information (such as a this. before the call)? Or is doing this illegal in its entirety?
EDIT: Just in case it helps... here is my Task class:
public class Task
{
bool displayAsPercent;
int currentItem;
int totalItems;
object result;
public System.Threading.Tasks.Task Action { get; private set; }
public string Description { get; private set; }
public bool IsComplete { get { return currentItem >= ItemCount; } }
public int TotalItems { get { return totalItems; } }
public object Result { get { return result; } }
public object Baggage { get; private set; }
public bool Started { get { return currentItem > 0; } }
public int ItemCount
{
get
{
if (displayAsPercent)
return 100;
else
return totalItems;
}
}
public int CompletedValue
{
get
{
if (displayAsPercent)
return (int)((float)((float)currentItem / (float)ItemCount) * 100.0f + 0.5f);
else
return currentItem;
}
}
public Task(string description, int stepCount, bool displayAsPercent, System.Threading.Tasks.Task task)
{
currentItem = 0;
Description = description;
totalItems = stepCount;
this.displayAsPercent = displayAsPercent;
Action = task;
}
public void Begin(Task previous) { if (previous != null) Baggage = previous.Result; ++currentItem; }
public void Advance() { ++currentItem; }
public void Advance(int increase) { currentItem += increase; }
public void Complete() { currentItem = totalItems; }
public void Finalize(object result) { this.result = result; }
}
modified 15-Nov-17 13:35pm.
|
|
|
|
|