|
I am pretty sure that will be one of the first help topics in the documentation (well I know this, because I had to look for it myself the other day, sorry no link).
|
|
|
|
|
so how did u resolved it...........any idea abt it...........thanks leppie.........!!!
|
|
|
|
|
Hello All -
I am looking for a C# Example using an Access DB without DataGrids.
Any Help would be appreciated.
Thanks!
|
|
|
|
|
It's hard to work out hwat you're asking here. Do you want to show one record per page ? Do you want to create a grid without using the control ( and if so, why ) ?
Once you've called your data source, be it access or whatever, you can display your data any way you want. What is it you're looking for here ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I am want to update one record at a time. I am looking to do a very simple and small maintenance program for contacts.
Thanks!
|
|
|
|
|
OK - so you add controls to show the data for the contact, whatever that is, and a button that calls SQL to update that contact with whatever the user types in.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Here is the issue that I am having:
When I fill out the form and leave some of the fields blank I get an SQL Error message that states this: No value given for one or more required parameters.
Here is the code block that does the update:
conProspect.Open();
OleDbCommand cmd = conProspect.CreateCommand();
cmd.CommandText = "Update Contacts set Last_Name=" + "'" + txtLastName.Text + "'" + ", " + "First_Name=" + "'" + txtFirstName.Text + "'" + ", " + "Company_Name=" + "'" + txtCompany.Text + "'" + ", " + "Job_Title='" + txtJobTitle.Text + "'" + ", " + "Business_Phone='" + txtBusPhone.Text + "'" + " Where Contact_ID =" + lngContactId;
cmd.ExecuteNonQuery();
conProspect.Close();
Thanks for the help
|
|
|
|
|
you need to read up on SQL injection attacks, unless you trust everyone who will use this code.
kruegersck wrote: + "'"
Why put this seperately ?
You should take the string you generate, copy it into Access and run it from there, or at least look at it to see why it's wrong. Stuff like Company_Name = '' shouldn't cause an error unless the DB does not allow the strings to be empty.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
This was one sample I found on the net. I am new to c# so I am looking for a good example to work off of.
If you know of one please add to post.
Thanks!
|
|
|
|
|
OK - how much of this code do you understand ? Copying examples from the web is not a good way to learn, you should work through a book first, then look for examples, but also look to fully understand any code you use.
There's a good article on SQL injection on code project, just search for it.
So, when you say you found an example, does this code match with your database schema at all ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I understand all the code just fine. I found the issue with one of my data base fields. What is the best practice for updating my table? This application will run on user desktop and it is not web based?
|
|
|
|
|
Well, best practice is to use a parameterised query or a stored proc. I suggest searching for hte article on SQL injection and reading it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for the info! I will read up on these two issues.
|
|
|
|
|
I'm unable to open up the "Field Explorer" of Crystal Report for setting up the parameters.......... It's not separate, its integrated into VS.NET 2003............i know its kinda silly question, but i'm kinda messed up with that............so pls help with steps to bring it back...........
|
|
|
|
|
|
If you call 11 minutes a lot of time, you need to learn to be more patient! I have had problems that took months to solve.
|
|
|
|
|
Hi All,
I have a windows form program, which runs and compiles fine.
but along with the form window, there is a console window (black "command prompt" screen)
that also launches, none of my other window program have this behavior.
where can I stop the black window from launching?
I looked at all the code and can't find it, so I'm assuming is some settings that I need to turn off.
again, thank you all for all the help you have provided to this newbie.
-JC
|
|
|
|
|
Your project thinks it is a console application.
Go to the project's properties and check that the "Output type:" setting is set to "Windows Application" and the "Startup object:" is set to your main WinForm's class.
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
Wow,
I must be blind, I went through that before and did not noticed that...
thank you for your help
-JC
|
|
|
|
|
I have a panel of (800 by 600) when i do a print preview I can see the complete panel but when i do the print it cuts the right side veritcal line. During the preview my panel right side border line still away from the margin line. Any idea please
|
|
|
|
|
Hi,
most printers can't print up to the edges of the page; the printer driver knows the
minimal margins, you can try to cross them through the page setup dialog, and IIRC you
can read the settings in PrintPageEventArgs (one of the DoPrintPage arguments) and should
take them into account.
|
|
|
|
|
Hello Everyone...i'm creating a code that will scan LDAP and Active Directory for a fax number given to users and then it will compare both servers and will generate a text file with the discrepancies on both servers(only the numbers that don't match). The program seems to work but for some reason in the output i get a couple of users who have the same fax number in both servers. i wonder if i created the foreach loops correctly...can someone please guide me?????
namespace fax
{
// This sorted collection provides easy access to the FaxEntry objects added to it
// It also overrides ToString() to facilitate easy writing of results to the text file
public class FaxEntries : SortedList<string,>
{
System.Text.StringBuilder sb = new StringBuilder();
public override string ToString()
{
// If list is not already built up
if (sb.Length == 0)
{
// header
sb.AppendLine("XPID\t\tDisplay Name\tLDAP Fax#\tAD Fax#");
sb.AppendLine("-------------\t--------------\t-------------\t-------------");
// Iterate the collection and output each FaxEntry object via it's (overrided) ToString() method
foreach (KeyValuePair<string,> CurrItem in this)
sb.AppendLine(CurrItem.Value.ToString());
}
// Return the results
return sb.ToString();
}
}
public class FaxEntry
{
public string XPID;
public string DisplayName;
public string LDAPFaxNumber;
public string ADFaxNumber;
public FaxEntry(string XPID, string DisplayName, string LDAPFaxNumber, string ADFaxNumber)
{
this.XPID = XPID;
this.DisplayName = DisplayName;
this.LDAPFaxNumber = LDAPFaxNumber;
this.ADFaxNumber = ADFaxNumber;
}
// create an easily readible one line entry for the result
public override string ToString()
{
return Pad(XPID) + Pad(DisplayName) + Pad(LDAPFaxNumber) + Pad(ADFaxNumber);
}
// Add an appropriate number of tab characters to create a nice looking display to the passed string
string Pad(string ToPad)
{
if (string.IsNullOrEmpty(ToPad))
return "\t\t";
return ToPad + (ToPad.Length < 8 ? "\t" : string.Empty) + "\t";
}
}
class Program
{
static FaxEntries Entries;
static void Main(string[] args)
{
// The two properties to compare
string ComparisonProperty2 = "facsimiletelephonenumber";
string ComparisonProperty1 = "fax";
// The two servers to attach to LDAP/Unix and AD
string Server1 = @"LDAP://";
string Server2 = @"LDAP://";
Entries = new FaxEntries();
// Call compare to perform the comparison
Compare(Server1, ComparisonProperty1, Server2, ComparisonProperty2);
// Write the results to a file
try
{
System.IO.File.WriteAllText(@"C:\Documents and Settings\My Documents\Visual Studio 2005\Projects\fax.txt", Entries.ToString());
// Write the results to the command line
Console.Write(Entries.ToString());
// Open a blank email
sendMyMail();
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
}
}
/// ////////////////////////////////////////////////////////////////////////
static void sendMyMail()
{
try
{
MailAddress from = new MailAddress("rillo@company.com");
MailAddress to = new MailAddress("mo@company.com");
MailMessage message = new MailMessage(from, to);
message.Body = "AD and LDAP lbpcsfax Discrepancies Report";
message.Body += Environment.NewLine;
message.Body += Environment.NewLine;
try
{
message.Attachments.Add(new Attachment(@"C:\Documents and Settings\My Documents\Visual Studio 2005\Projects\fax.txt"));
}
catch (Exception e1)
{
message.Body += "Will not attach " + Entries + " because " + e1.Message;
}
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "AD and LDAP fax Discrepancies Report";
message.Priority = MailPriority.Normal;
message.SubjectEncoding = System.Text.Encoding.UTF8;
SmtpClient client = new SmtpClient("mailhost.company.com");
try
{
client.Send(message);
}
catch (Exception exx)
{
Console.WriteLine("Error sending email " + exx.GetBaseException() + " " + exx.InnerException);
}
message.Dispose();
}
catch (Exception e)
{
Console.WriteLine("Error sending email " + e.GetBaseException() + " " + e.InnerException);
}
}
/// ////////////////////////////////////////////////////////////////////////////////////
static string GetPropertyForDisplay(SearchResult result, string Name)
{
if (result == null)
return string.Empty;
ResultPropertyValueCollection Items = result.Properties[Name];
if (Items != null)
{
if (Items.Count == 1)
return Name + " = " + Items[0].ToString();
else
{
string ret = Name + " = ";
foreach (object myKey in Items)
if (myKey != null)
ret += "\t" + myKey.ToString();
return ret;
}
}
return string.Empty;
}
static string GetProperty(SearchResult result, string Name)
{
if (result == null)
return string.Empty;
ResultPropertyValueCollection Items = result.Properties[Name];
if (Items != null)
{
if (Items.Count == 1)
return Items[0].ToString();
else
{
string ret = "";
foreach (object myKey in Items)
if (myKey != null)
ret += "\t" + myKey.ToString();
return ret;
}
}
return string.Empty;
}
static void Compare(string Server1, string PropertyToCompare1, string Server2, string PropertyToCompare2)
{
// Create the new FaxEntries Collection, one for each entry we find on either server property
Entries = new FaxEntries();
// Go get the matching LDAP users
SearchResultCollection server1Results = GetListByProperty(Server1, PropertyToCompare1, "uid");
SearchResultCollection server2Results = GetListByProperty(Server2, PropertyToCompare2, "sAMAccountName");
//added
if (server1Results != null)
{
foreach (SearchResult CurrItem in server1Results)
{
string sAMAccountName = GetProperty(CurrItem, "uid");
Entries.Add(sAMAccountName.ToLower(), new FaxEntry(sAMAccountName, GetProperty(CurrItem, "givenName"), GetProperty(CurrItem, PropertyToCompare1), null));
}
}
else
{
Console.WriteLine("server1Results returned nothing");
}
if (server2Results != null)
{
// Repeat on the second server with the second property and compare, adding as necessary
foreach (SearchResult CurrItem in server2Results)
{
string sAMAccountName = GetProperty(CurrItem, "sAMAccountName");
if (Entries.ContainsKey(sAMAccountName.ToLower()))
{
Entries[sAMAccountName.ToLower()].ADFaxNumber = GetProperty(CurrItem, PropertyToCompare2);
}
else
{
if (!Entries.ContainsKey(sAMAccountName.ToLower()))
{
Entries.Add(sAMAccountName.ToLower(), new FaxEntry(sAMAccountName, GetProperty(CurrItem, "givenName"), null, GetProperty(CurrItem, PropertyToCompare2)));
}
}
}
}
else
{
Console.WriteLine("server2 Results returned nothing");
}
}
static SearchResultCollection GetListByProperty(string LDAPPath, string PropertyToPerformComparisonAgainst, string userTag)
{
DirectoryEntry entry = new DirectoryEntry(LDAPPath);
DirectorySearcher usersearch = new DirectorySearcher(entry);
string myFilter = string.Empty;
entry.AuthenticationType = AuthenticationTypes.None;
if (userTag.ToLower().Equals("uid"))
{
myFilter = "(&(" + userTag + "=*)(" + PropertyToPerformComparisonAgainst + "=*)(objectClass=lborgperson))";
}
else
{
myFilter = "(&(" + userTag + "=*)(" + PropertyToPerformComparisonAgainst + "=*))";
}
Console.WriteLine(LDAPPath);
Console.WriteLine(myFilter);
try
{
usersearch.Filter = myFilter;
SearchResultCollection result = usersearch.FindAll();
Console.WriteLine(result.Count.ToString());
return result;
}
catch (Exception ex)
{
Console.WriteLine("Exception caught:" + ex.InnerException + " hmm " + ex.GetBaseException());
}
usersearch.Dispose();
entry.Close();
entry.Dispose();
return null;
}
}
}<
|
|
|
|
|
You'll get a better response if you use <pre></pre> tags around your code.
FYI: LDAP is a protocol and it is also used by AD
|
|
|
|
|
There's an option in Crystal Report like "To set up record selection using Select Expert"........but I notice that I would be able to only hard-code the values that are already existing in the database field.........rather I'm looking for something where I can get the value selected directly from the combobox..........am I clear with those lines.........I need help on this............TIA
|
|
|
|
|
you can use a parameter field, and set it at runtime, you could use a forumla field and change the formula text at runtime to return your value, or you could find a new product to use, i'm traped in the same place you are, trying to make CR dynamic...i've managed to an extent thanks to several online examples and "Crystal Reports .NET Programming" by Brian Bischof(not sure about the first name) but a lot of the features that made it so great for programmers have been removed in later versions the version for vs 6 you could almost build a whole report at runtime, and in 2008 you have to struggle to change anything at runtime, espically with any kind of chart. If you find a good alternative to CR please let me know.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|