|
First, OP refers to having used "some barcode fonts". So he doesn't need a complete barcode generator.
Then, when posting code, please wrap it in tags like these:
<pre lang="c#">YourCodeHere();</pre>
That makes code much more readable, which is important, especially in an extend like what's given here.
How about making an article of that? It could be interesting for many.
Ciao,
luker
|
|
|
|
|
You should post links to this code, and, if you are not the author, credit the author. The code came from: [^], and/or: [^].
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
modified 6-Feb-14 3:32am.
|
|
|
|
|
Both your links point to the same source.
But that hardly justifies univoting.
Ciao,
luker
|
|
|
|
|
I have edited my post to include a correct reference to the (possibly) second file used.
The code may have also come from here: [^].
That's really great that your psychic powers tell you who the people are that down-voted
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
What's wrong with the responses you got two days ago[^]?
Ciao,
luker
|
|
|
|
|
I am unable to get the expected output and i want to try only with c# code
|
|
|
|
|
Then comment on an answer and tell the person that was trying to help you, where you have problems with putting his/her proposal into action.
"It does not work" is not the sort of comment that will help anyone.
Tell what you have and what you need instead.
Tell what's happening and what you're expecting instead.
And as far as I saw it, that's all C#.
Ciao,
luker
|
|
|
|
|
Hey Guys,
I have my SQL Server Database on machineX i name that as "OtherMachine"
I have installed my visual Studio on current machine i name that as "MyMachine".
I created windows forms on MyMachine and try to connect with Database on "OtherMachine"
View-->Server Explorer-->Add Connection-->Choose Microsoft SQL Server
In Add Connection window:
when i give Server name as
Scenario1:
OtherMachine\SQLEXPRESS
i could not find any database in the dropdown list. i get an error (Provider: SQL Network Interfaces, error:26 - Error Locating Server/Instance Specified)
But the Database are present in "OtherMachine"
Scenario2:
MyMachine\SQLEXPRESS (connecting to local database on MYMachine)
in dropdown list i get the datbase listed. its successfull.
Issue: am not able to connect to database on "OtherMachine".
Please assist.
|
|
|
|
|
|
I have a machine with SQL 2008 R2 Express Edition installed, and i have created a Database in that machine.
I cannot start "SQL Server Agent" - getting Remote Procedure Call Failed Error.
But other 2 are in running state (SQL Server (SQLEXPRESS) & SQL Server Browser)
Is that i cannot connect to this Database using the SQL 2008 R2 Express edition ????
Do i need to have SQL Server 2008 R2 installed ??
Please assist.
|
|
|
|
|
You cannot start the SQL Agent service because SQL Express doesn't include that component.
For the connection problems, did you read the blog post I linked to? Which steps from that post have you tried?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You may also want to make sure that port 1433 is open if there is a firewall in the mix.
Thanks
JD
http://www.seitmc.com/seitmcWP
|
|
|
|
|
try
{
string s = "INSERT INTO [Students Records] (Name,Age,Class,Gender,Guardian's Name,Contact.No,Address,Email-Address) VALUES(@Name,@Age,@Class,@Gender,@Guardian's Name,@Contact.No,@Address,@Email-Address)";
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand(s,con);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Name", textBox1.Text);
cmd.Parameters.AddWithValue("@Age", textBox2.Text);
cmd.Parameters.AddWithValue("@Class", textBox3.Text);
cmd.Parameters.AddWithValue("@Gender", textBox4.Text);
cmd.Parameters.AddWithValue("@Guardian's Name", textBox5.Text);
cmd.Parameters.AddWithValue("@Contact.No", textBox6.Text);
cmd.Parameters.AddWithValue("@Address", textBox7.Text);
cmd.Parameters.AddWithValue("@Email-Address", textBox8.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Saved!");
}
My query can't executed successfully please help ??
|
|
|
|
|
You can't have the "'" in Guardian's Name. What database are you using?
|
|
|
|
|
Member 10564850 wrote: My query can't executed successfully please help ??
As Griff mentioned on Saturday:
Just remember in future - the better the info you give us, the quicker we can give you a solution!
Once again, you've posted your code, but not the error message, which leaves us to play another game of "guess the error".
Assuming the problem is with the column names containing special characters, the quick fix is to wrap the affected column names in square brackets. You'll also need to fix the parameter names:
string s = "INSERT INTO [Students Records] (Name, Age, Class, Gender, [Guardian's Name], [Contact.No], Address, [Email-Address]) VALUES(@Name, @Age, @Class, @Gender, @GuardiansName, @ContactNo, @Address, @EmailAddress)";
A better solution is to change your database structure so that the table and column names do not contain anything other than letters and numbers - no spaces, no punctuation, and no extended characters.
The same restrictions apply to parameter names.
If that doesn't solve the problem, then you'll need to provide the details of the exception being thrown when you try to execute the query.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Whoops! Already moved. Sorry!
|
|
|
|
|
Answered here[^].
..and now you know "why" it is not done.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Again, you're putting spaces and special characters in the parameter names.
DO NOT USE SPACES AND SPECIAL CHARACTERS IN TABLE NAMES, FIELD NAMES AND PARAMETER NAMES!
Your field names should be something like this:
Name, Age, Class, Gender, GuardianName, ContactPhone, Address, EmailAddress
By making the code more "eyeball friendly" to read, you are giving yourself headaches debugging the resulting code. "Eyeball friendly" is NOT "compiler friendly"!
|
|
|
|
|
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
Hi,
I am using MySQL database in my C# .NET application and saving all dates in the database as UTC_TIMESTAMP
I want to know to display it for the user in his own local time according to his Microsoft Windows?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
Try reading the documentation on the DateTime structure, here[^].
Dim databaseUtcTime = dateTimeFromDatabase
databaseUtcTime = databaseUtcTime.SpecifyKind(DateTimeKind.Utc)
Debug.WriteLine(String.Format("UtcTime: {0}", databaseUtcTime.ToString()))
Debug.WriteLine(String.Format("LocalTime: {0}", databaseUtcTime.ToLocalTime().ToString()))
|
|
|
|
|
Alright, this is not exactly a programming question, but I also doubt that it would fit into the Lounge.
Situation: I am currently implementing the Syslog Protocol in .Net, starting with the Base classes (Message, Header, Struct. Data). The Header contains a timestamp which's formatting is exactly defined.
A timestamp may look as follows:
2014-2-4T14:22:56.235Z+1
2014-2-4T14:22:56.235Z-1.5
2014-2-4T14:22:56.235123Z+1
What I have done so far is that I consider System.DateTime being unuseable as timestamp, even with a wrapper around it it would be highly difficult since setting a single field (e.g. Day, Year, Month and so on) is only possible by parsing an entire time string, or adding a Time span.
Now to avoid these circumstances, I have implemented the following class SyslogTimestamp:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Springlog.Com.Messaging
{
public class SyslogTimestamp
{
#region Properties
static short GetDayMaxDaysOfMonth(int month, int year)
{
if (month != 2)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
return 31;
}
else
{
return 30;
}
}
else
{
if (IsLeapYear(year))
{
return 29;
}
return 28;
}
}
private static bool IsLeapYear(int year)
{
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
return true;
}
return false;
}
return true;
}
return false;
}
int year;
public int Year
{
get { return year; }
}
int month;
public int Month
{
get { return month; }
}
int dayOfMonth;
public int DayOfMonth
{
get { return dayOfMonth; }
}
int hours;
public int Hours
{
get { return hours; }
}
int minutes;
public int Minutes
{
get { return minutes; }
}
int seconds;
public int Seconds
{
get { return seconds; }
}
int miliseconds;
public int Miliseconds
{
get { return miliseconds; }
}
double utcOffset;
public double UtcOffset
{
get { return utcOffset; }
set { utcOffset = value; }
}
#endregion
public SyslogTimestamp()
{
Reset();
}
public SyslogTimestamp(string timestamp)
{
Reset();
FromString(timestamp);
}
public SyslogTimestamp(DateTime timestamp)
{
Reset();
FromDateTime(timestamp);
}
private void Reset()
{
miliseconds = 0;
seconds = 0;
minutes = 0;
hours = 0;
dayOfMonth = 0;
month = 1;
year = 1;
utcOffset = 0;
}
public bool FromString(string dateTime)
{
Regex splitRegex = new Regex("([0-9]{4})-([1-9]|[1][0-2])-([0-2]?[0-9]|[3][0-1])[T]([0-1]?[0-9]|[2][0-3])[:]([0-5]?[0-9])[:]([0-5]?[0-9])?.?([0-9]{1,6})[Z]([+-][0-9]|[+-]?[0][1][0-2])", RegexOptions.IgnoreCase);
Match timestamp = splitRegex.Match(dateTime);
if (timestamp.Groups.Count == 9)
{
AddYears(Int32.Parse(timestamp.Groups[1].Value));
AddMonths(Int32.Parse(timestamp.Groups[2].Value));
AddDays(Int32.Parse(timestamp.Groups[3].Value));
AddHours(Int32.Parse(timestamp.Groups[4].Value));
AddMinutes(Int32.Parse(timestamp.Groups[5].Value));
AddSeconds(Int32.Parse(timestamp.Groups[6].Value));
AddMilliseconds(Int32.Parse(timestamp.Groups[7].Value));
utcOffset = Int32.Parse(timestamp.Groups[8].Value);
return true;
}
else
{
return false;
}
}
public string ToFormattedString()
{
string timezonPreSign = "+";
if (utcOffset < 0)
{
timezonPreSign = "";
}
return string.Format("{0}-{1}-{2}T{3}:{4}:{5}.{6}Z{7}{8}", year, month, dayOfMonth, hours, minutes, seconds, miliseconds, timezonPreSign, utcOffset);
}
public override string ToString()
{
return this.ToFormattedString();
}
public void FromDateTime(DateTime timestamp, bool convertToUtc = true)
{
TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(timestamp);
if (convertToUtc)
{
timestamp.Add(utcOffset);
this.utcOffset = 0;
}
else
{
this.utcOffset = utcOffset.Hours + (utcOffset.Minutes / 100);
}
AddMilliseconds(timestamp.Millisecond);
AddSeconds(timestamp.Second);
AddMinutes(timestamp.Minute);
AddHours(timestamp.Hour);
AddDays(timestamp.Day);
AddMonths(timestamp.Month);
AddYears(timestamp.Year);
}
public void Add(TimeSpan timeSpan)
{
AddMilliseconds(timeSpan.Milliseconds);
AddSeconds(timeSpan.Seconds);
AddMinutes(timeSpan.Minutes);
AddHours(timeSpan.Hours);
AddDays(timeSpan.Days);
}
public void AddMilliseconds(int val)
{
if (val + miliseconds >= 1000)
{
AddSeconds( val / 1000);
miliseconds = (val % 1000);
}
else
{
miliseconds += val;
}
}
private void AddSeconds(int val)
{
if (seconds + val >= 60)
{
AddMinutes(val / 60);
seconds = (val % 60);
}
else
{
seconds += val;
}
}
private void AddMinutes(int val)
{
if (minutes + val >= 60)
{
AddMinutes(val / 60);
minutes = (val % 60);
}
else
{
minutes += val;
}
}
private void AddHours(int val)
{
if (minutes + val >= 24)
{
AddDays (val / 24);
minutes = (val % 24);
}
else
{
minutes += val;
}
}
private void AddDays(int val)
{
short dayCount = GetDayMaxDaysOfMonth(month, year);
if (dayOfMonth + val > dayCount)
{
AddMonths(val / dayCount);
dayOfMonth = (val % dayCount);
}
else
{
dayOfMonth += val;
}
}
private void AddMonths(int val)
{
if (month + val > 12)
{
AddYears(val / 12);
month = (val % 12);
}
else
{
month += val;
}
}
private void AddYears(int val)
{
year += val;
}
public override bool Equals(object o)
{
if (o is SyslogTimestamp)
{
return DoMatch((SyslogTimestamp)o, this);
}
else
{
return false;
}
}
public static bool DoMatch(SyslogTimestamp a, SyslogTimestamp b)
{
bool doMatch = (a.year == b.Year)
&& (a.month == b.Month)
&& (a.dayOfMonth == b.DayOfMonth)
&& (a.hours == b.Hours)
&& (a.minutes == b.Minutes)
&& (a.seconds == b.Seconds)
&& (a.miliseconds == b.Miliseconds)
&& (a.utcOffset == b.UtcOffset);
return doMatch;
}
public static bool operator ==(SyslogTimestamp a, SyslogTimestamp b)
{
if (System.Object.ReferenceEquals(a, b))
{
return true;
}
if (((object)a == null) || ((object)b == null))
{
return false;
}
return DoMatch(a, b);
}
public static bool operator !=(SyslogTimestamp a, SyslogTimestamp b)
{
return !(a == b);
}
public static bool operator <(SyslogTimestamp a, SyslogTimestamp b)
{
if (a.Year < b.Year) { return true; }
if (a.Year > b.Year) { return false; }
if (a.Month < b.Month) { return true; }
if (a.Month > b.Month) { return false; }
if (a.DayOfMonth < b.DayOfMonth) { return true; }
if (a.DayOfMonth > b.DayOfMonth) { return false; }
if ((a.Hours + a.UtcOffset) < (b.Hours + b.UtcOffset)) { return true; }
if ((a.Hours + a.UtcOffset) > (b.Hours + b.UtcOffset)) { return false; }
if (a.Minutes < b.Minutes) { return true; }
if (a.Minutes > b.Minutes) { return false; }
if (a.Seconds < b.Seconds) { return true; }
if (a.Seconds > b.Seconds) { return false; }
if (a.Miliseconds < b.Miliseconds) { return true; }
if (a.Miliseconds > b.Miliseconds) { return false; }
return false;
}
public static bool operator >(SyslogTimestamp a, SyslogTimestamp b)
{
if (a.Year > b.Year) { return true; }
if (a.Year < b.Year) { return false; }
if (a.Month > b.Month) { return true; }
if (a.Month < b.Month) { return false; }
if (a.DayOfMonth > b.DayOfMonth) { return true; }
if (a.DayOfMonth < b.DayOfMonth) { return false; }
if ((a.Hours + a.UtcOffset) > (b.Hours + b.UtcOffset)) { return true; }
if ((a.Hours + a.UtcOffset) < (b.Hours + b.UtcOffset)) { return false; }
if (a.Minutes > b.Minutes) { return true; }
if (a.Minutes < b.Minutes) { return false; }
if (a.Seconds > b.Seconds) { return true; }
if (a.Seconds < b.Seconds) { return false; }
if (a.Miliseconds > b.Miliseconds) { return true; }
if (a.Miliseconds < b.Miliseconds) { return false; }
return false;
}
public static bool operator >=(SyslogTimestamp a, SyslogTimestamp b)
{
return (a > b) || DoMatch(a, b);
}
public static bool operator <=(SyslogTimestamp a, SyslogTimestamp b)
{
return (a < b) || DoMatch(a, b);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
Of course I have Unit Tests to check the integrity of the data handling within that class:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Springlog.Com.Messaging;
namespace Springlog.Com.Messaging.UnitTests
{
[TestClass]
public class SyslogTimestampUnitTest
{
[TestMethod]
public void SyslogTimestampComparisonIntegrity()
{
SyslogTimestamp timestamp1 = new SyslogTimestamp();
SyslogTimestamp timestamp2 = new SyslogTimestamp();
SyslogTimestamp timestamp3 = new SyslogTimestamp();
SyslogTimestamp timestamp4 = new SyslogTimestamp();
timestamp1.FromDateTime(DateTime.Now);
timestamp2.FromDateTime(DateTime.Now.AddDays(-1));
timestamp3 = timestamp1;
timestamp4.FromDateTime(DateTime.Now.AddMinutes(2));
Assert.AreEqual(true, (timestamp1 > timestamp2));
Assert.AreEqual(true, (timestamp4 > timestamp1));
Assert.AreEqual(false, (timestamp1 < timestamp2));
Assert.AreEqual(true, (timestamp1 >= timestamp2));
Assert.AreEqual(false, (timestamp1 <= timestamp2));
Assert.AreEqual(true, (timestamp1 == timestamp3));
Assert.AreEqual(false, (timestamp1 != timestamp3));
Assert.AreEqual(false, (timestamp1 == timestamp4));
Assert.AreEqual(false, (timestamp1 == timestamp2));
}
[TestMethod]
public void SyslogTimestampStringConversionIntegrity()
{
DateTime now = DateTime.Now;
SyslogTimestamp timestamp = new SyslogTimestamp();
SyslogTimestamp timestamp2 = new SyslogTimestamp();
timestamp.FromDateTime(now);
timestamp.UtcOffset = 1;
Assert.AreEqual(true, timestamp2.FromString(timestamp.ToFormattedString()));
Assert.AreEqual(true, (timestamp2 == timestamp));
}
}
}
Now my question is: Can I achieve the same with System.DateTime?
I seriously doubt that, since System.DateTime's ParseExact method tends to have problems dealing with a variable amount of microseconds, and does not provide any field to store the UTC Offset.
Edit: I provided the new class implementation, since I have added various improvements.
Clean-up crew needed, grammar spill... - Nagy Vilmos
modified 5-Feb-14 8:52am.
|
|
|
|
|
personally I would never re-write it. I once tried and though it was more than a reasonable effort, the amount of rules and things to think of becomes very large and does not outwheigh the disadvantages of being stuck with the standard DateTime.
([SMALL RANT]And I'm now working with Java's GregorianCalendar, how I wish I had a DateTime object [/SMALL RANT])
Marco Bertschi wrote: since System.DateTime's ParseExact method tends to have problems dealing with a variable amount of microseconds, and does not provide any field to store the UTC Offset.
Variable microseconds can be handled with a few lines of business logic I think and for the UTC Offset you could create a new DateTime Object that inherits from the DateTime class? (just a quick thought)
good luck.
|
|
|
|
|
V. wrote: Variable microseconds can be handled with a few lines of business logic I think
The big deal is that the Syslog Timestamp has special characters in it, in order to make it better parseable. ParseExact can't handle them properly, somehow.
V. wrote: for the UTC Offset you could create a new DateTime Object that inherits from the DateTime class? (just a quick thought)
And then I'd end up with what I already have, since the UTC Offset must be recognized when comparing two types of the new datetime class.
In the end I'd say that it is a reasonable amount of work, especially since Date/Time stuff isn't going to change too soon, and if it has proven itself worth the work it will last longer than both of us will ever live.
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|