|
For an Active Directory utility I wrote, I have references to:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.DirectoryServices.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.DirectoryServices.AccountManagement.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.DirectoryServices.Protocols.dll
|
|
|
|
|
I managed to write what I needed with those references as well. Thank you for your reply.
Time is the fire in which we burn.
|
|
|
|
|
hey all im using visual studio 2015 rc right and i want to connect a sql table to visual studios, im watching a tutorial on youtube on the video the guy (uses 2010)goes to add new item > local database / and i dont have that option? is it removed? or has the name changed?
modified 21-Jul-15 6:30am.
|
|
|
|
|
Are you using the same version as the person in the video?
There will probably be a small difference between the free and the full version.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
no im using 2015 rc he is using 2010 , i wanted to know how do i do it on 2015
|
|
|
|
|
"release candidate"?
Of the community edition?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i think so , its the 2015 rc but iguess its the comunity one, (free one)
|
|
|
|
|
The free edition is of course limited in functionality.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
This is not a C# issue. However, I just tried it on VS 2013 Express and the option is not available, although on VS 2010 Express it is. I suggest you contact Microsoft.
|
|
|
|
|
Doing some research on techniques for passing a variable length list of parameters of different types, I came across this: [^]
"Another possible solution that doesn’t require you to create a new type is using a Func delegate. Like so:
Func<int, string, Tuple<int, string>> c = Tuple.Create;
var list = new List<Tuple<int, string>>
{
c(1, "apples"),
c(2, "kiwiws"),
};" I've never seen the Tuple.Create method used in this way, and I am real curious about what is going on under the hood.
Appreciate hearing your thoughts on this.
thanks, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 20-Jul-15 16:10pm.
|
|
|
|
|
Hi Bill,
there's not a lot of magic going on there. c is basically declared as an alias for Tuple.Create(int, string). You could remove the declaration of c and replace c(.., ..) by Tuple.Create(.., ..) or new Tuple(.., ..). Whether or not this is more readable or in just any way better is up to personal taste I guess.
cheers, Sascha
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thanks, Sascha ! I've never seen this way of creating a "typed alias" before, and I've been working with .NET intensely for a long time
cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Hi
I download code attached and do exact instructions in this article:
Duplex Service in WCF[^]
but client cannot connect to server.
what is the problem?
|
|
|
|
|
When you have a problem with code you got from an article, you should ask in the forum at the end of the article. It's very unlikely that the author of the piece will just happen on by and open your question.
|
|
|
|
|
I'd also recommend to include any exceptions or errors that you get. When you say that it can't connect, there's a dosen reasons, and the most likely is a firewall.
Try pinging the remote address. If it doesn't answer, then the sample-code won't work either.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I have a simple POS application. I have included the Microsoft.PointOfService and Microsoft.PointOfService.ControlBase to my project and save it in my deployment project too.
Do I need to do anything else? or just deploying those two files is enough?
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
I would think that is a question for Microsoft and would depend on their licensing.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I'm building a simple windows form app which stores all of my DVD's (pet project, just for learning; I'm sure there are plenty already out there). I'm able to add items into the database (azure SQL Server) perfectly, even leaving some or most textboxes blank (the title column is setup as NOT NULL in my table) but I can't get it to retrieve any data.
Here is my OnClick method:
private void searchButton_Click(object sender, EventArgs e)
{
string qString = @"SELECT Title, Director, Genre, ReleaseYear, Length, NumberofDisks, Description FROM Base WHERE Title = '" + titleTextbox.Text + "' AND Director = '" + directorTextbox.Text + "' AND Genre = '" + genreCombobox.GetItemText(genreCombobox.SelectedItem) + "' AND ReleaseYear = '" + yearCombobox.GetItemText(yearCombobox.SelectedItem) + "' AND Length = '" + lengthTextbox.Text + "' AND NumberOfDisks = '" + numberOfDisksTextbox.Text + "' AND Description = '" + descriptionTextbox.Text + "';";
string cString = @"Server=MyAzureServer,MyPortNumber;Database=MyDatabase;User ID=me@MyAzureServer;Password=MyPassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
DataTable dTable = new DataTable();
SqlConnection sConnection = new SqlConnection(cString);
sConnection.Open();
using(SqlCommand sCommand = new SqlCommand(qString, sConnection))
{
try
{
SqlDataReader sReader = sCommand.ExecuteReader();
dTable.Load(sReader);
}
catch(SqlException sEx)
{
MessageBox.Show(sEx.Message);
}
resultsDataGridView.DataSource = dTable;
}
sConnection.Close();
}
and here is my table:
CREATE TABLE [dbo].[Base]
(
[MediaID] [int] IDENTITY(1,1) PRIMARY KEY,
[Title] [nvarchar](50) NOT NULL,
[Director] [nvarchar](50) NULL,
[Genre] [nvarchar](50) NULL,
[ReleaseYear] [date] NULL,
[Length] [time] NULL,
[NumberOfDisks] [int] NULL,
[Description] [nvarchar](200) NULL
)
I absolutely realize this is open to SQL injection. My plan is to just 'get it working' and then I will go back over it and and change to parameterized queries (I have to read up on how to use them). The program compiles and runs fine. When I click the search button with all or any of the textboxes filled, it returns no results in the datagridview. The white grid shows up but it is empty. I can query the database directly and get the results I'm looking for, but not programatically. Do I need to build the query using logic? Since almost all of my columns accept null (except Title) I'm assuming leaving a field blank wouldn't be a problem, but even if I enter data into all of the available textboxes(exact matches including case just to be certain) I get no results. Am I missing something small and stupid?
Can anyone give me any help or hints? Please no laughing at my code or making fun of me
Thanks,
John
"Only a fool learns from his own mistakes, but a wise man learns from the mistakes of others." -Unknown
|
|
|
|
|
Please learn to use parameterized statements and NEVER use concatenation to provide values, especially values from the user.
That will likely solve your problem.
|
|
|
|
|
You said that you know that the code is vulnerable to SQL injections but that is not the only reason why to use parameters. Another thing is that they help you with conversions. Consider for example dates and the date format or numbers. Using a correct format is difficult when the data is in text format.
Few other reasons why the query might not return any data
- There are a lot of conditions. Since they are defined in the WHERE clause you cannot leave any of them empty and expect that the condition would be ignored. If a text box is empty the comparison will still take place
- The operator for all conditions is AND so all the the conditions you have specified must be satisfied by a single row
- You use equality in all comparisons. For example description is compared to the value from the text box using equality. This means that the text must match exactly and completely. This prbably isn't what you're after. Perhaps LIKE comparison?
|
|
|
|
|
Yeah, it'll help you to "get it working" if you just went to parameterized queries to begin with to help you avoid problems such as these and also makes it much easier to debug when you do run into problems.
Your WHERE clause is screwing you over somehow. Rewrite to help you debug the problem and make sure the parameters you're passing in are expected and correct.
|
|
|
|
|
If you leave one of your boxes open, let's say length, then your sql includes
WHERE length = ''
so you'll only get records where the length is empty. If you want to ignore a field if it is empty then your SQL needs to look like
WHERE
(@field1 IS NULL OR field1 = @field1)
AND (@field2 IS NULL OR field2 = @field2)
@field1 and @field2 are your input params, and field1 and field2 are the matching columns in your database. In order for this to work it'll be easier if you switch to params first. So if you want to ignore an element from the query then set it's param to dbnull.value if the associated textbox is empty.
|
|
|
|
|
John L. DeVito wrote: My plan is to just 'get it working' and then I will go back over it and and change to parameterized queries
That's a very bad plan. There's a good chance that you'll miss something, or forget to do it, or run out of time, or lose interest and move on to the next project...
Plus, as others have pointed out, using string concatenation to build your query will introduce new problems that you'll have to fix, which wouldn't be the case if you used properly parameterized queries.
Parameterized queries aren't particularly hard, particularly as you're using ADO.NET and SQL Server:
private void searchButton_Click(object sender, EventArgs e)
{
const string ConnectionString = @"Server=MyAzureServer,MyPortNumber;Database=MyDatabase;User ID=me@MyAzureServer;Password=MyPassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
const string Query = @"SELECT
Title,
Director,
Genre,
ReleaseYear,
Length,
NumberofDisks,
Description
FROM
Base
WHERE
(NullIf(@Title, '') Is Null Or Title = @Title)
AND
(NullIf(@Director, '') Is Null Or Director = @Director)
AND
(NullIf(@Genre, '') Is Null Or Genre = @Genre)
AND
(NullIf(@ReleaseYear, '') Is Null Or ReleaseYear = @ReleaseYear)
AND
(NullIf(@Length, '') Is Null Or Length = @Length)
AND
(NullIf(@NumberOfDisks, '') Is Null Or NumberOfDisks = @NumberOfDisks)
AND
(NullIf(@Description, '') Is Null Or Description = @Description)
;";
DataTable dTable = new DataTable();
using (SqlConnection connection = new SqlConnection(ConnectionString))
using (SqlCommand command = new SqlCommand(Query, connection))
{
command.Parameters.AddWithValue("@Title", titleTextbox.Text);
command.Parameters.AddWithValue("@Director", directorTextbox.Text);
command.Parameters.AddWithValue("@Genre", genreCombobox.GetItemText(genreCombobox.SelectedItem));
command.Parameters.AddWithValue("@ReleaseYear", yearCombobox.GetItemText(yearCombobox.SelectedItem));
command.Parameters.AddWithValue("@Length", lengthTextbox.Text);
command.Parameters.AddWithValue("@NumberOfDisks", numberOfDisksTextbox.Text);
command.Parameters.AddWithValue("@Description", descriptionTextbox.Text);
connection.Open();
using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
{
dTable.Load(reader);
}
}
resultsDataGridView.DataSource = dTable;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm am puzzled by this:
1. I have a Dictionary whose Keys are Enumeration-Values, and whose Values are of Type Action<Control1, Control2>
2. At run-time I am calling a method that adds a LocationChanged EventHandler which is constructed as a lambda on-the-fly ... to Control1. This LocationChanged EventHandler will execute the Action described in #1 which will change the other Control, Control2.
When Control2 refers to a Form, and, at run-time, that Form has been closed using its Close Button: my impression, up to now, has been that references to that Form would be garbage collected, so if Control1 (another Form) was moved, and the LocationChanged event was triggered which attempted to modify Control1 (closed Form), I would expect a null reference error.
But, there is no run-time error thrown; I infer from that there must be valid references to the closed Form "still around."
I think I better illustrate this with a dumbed-down bare-bones code example: a WinForms project with a MainForm 'Form1, and second Form, 'Form2:
enum SomeEnum
{
whatever1,
whatever2
}
private Dictionary<SomeEnum, Action<Control, Control>> EnumToAction;
private void Form1_Load(object sender, EventArgs e)
{
EnumToAction = new Dictionary<SomeEnum, Action<Control, Control>>
{
{
SomeEnum.whatever1, (control, control1) =>
{
control1.Top = control.Top;
}
},
{
SomeEnum.whatever2, (control, control1) =>
{
control1.Left = control.Right;
}
}
};
Form2 f2 = new Form2();
f2.Show();
SetAction(this, f2, SomeEnum.whatever1);
}
private void SetAction(Control bControl, Control dControl, SomeEnum someenum)
{
bControl.LocationChanged += (sender, args) =>
{
EnumToAction[someenum](bControl, dControl);
};
EnumToAction[someenum](bControl, dControl);
} Running the above code, then closing 'Form2 by clicking its Form Close Button, and then moving 'Form1 does not then throw an error which makes me believe that the reference to 'Form2 in that created-lambda EventHandler must still be valid.
I guess I could keep a Dictionary of Control, EventHandler around to deal with this ... to explicitly remove EventHandlers ... but, then, you've got different types of EventHandlers (differences in parameters) to deal with.
Ideas ?
thanks, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 19-Jul-15 10:40am.
|
|
|
|
|
Everyone knows that anonymous delegates cannot be removed so obviously there are places where they should not be used!
But what if?
What if the add and remove mechanisms are set up at the same time? Sure the delegate code is anonymous but, as you say in your message, a reference can be kept.
I have lambdaphobia so here is the great idea in old school code.
public class Form1 : Form {
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
this.Text = "One";
Form f = new Form();
f.Text = "Two";
f.Show();
ISeeAWitch(this, f);
}
private void ISeeAWitch(Form bControl, Form dControl) {
EventHandler locationChanged = new EventHandler(delegate(Object sender, EventArgs e) {
dControl.Left = bControl.Right;
dControl.Top = bControl.Top;
});
bControl.LocationChanged += locationChanged;
dControl.FormClosed += new FormClosedEventHandler(delegate(Object sender, FormClosedEventArgs e) {
if (bControl != null) {
bControl.LocationChanged -= locationChanged;
MessageBox.Show("I'm off");
}
});
locationChanged(null, null);
}
}
Alan.
|
|
|
|
|