|
If you're looking to clamp the date range to be single month values, a simple extension method will return the last date of a month from the start date:
public static DateTime ToLastDayInMonth(this DateTime date)
{
return new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
}
This space for rent
|
|
|
|
|
- Use a Spinner with a Minimum and Maximimum
- Use a Slider with a Minumum and Maximum
- Use a DatePicker with a Start and End date
- Use a Calendar control with a Start and End date
- ditch the textbox in this case
|
|
|
|
|
i am trying to get an sqlite project c# wpf application working with entity framework so that when i start my application and the sqlite file is missing it would create it. and the schema would come from the context just like entity framework codefirst
this is what i got so far:
my app.config
="1.0"="utf-8"
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
</configuration>
the following is my code for the entity and context. and how i initiate them:(i got them from reading tutorials)
class ChinookContext : DbContext
{
public DbSet Artists { get; set; }
public DbSet Albums { get; set; }
public ChinookContext(string filename)
: base(new SQLiteConnection()
{
ConnectionString =
new SQLiteConnectionStringBuilder() { DataSource = filename, ForeignKeys = true }
.ConnectionString
}, true)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions
.Remove();
}
}
public class Artist
{
public Artist()
{
Albums = new List();
}
public long ArtistId { get; set; }
public string Name { get; set; }
public virtual ICollection Albums { get; set; }
}
public class Album
{
public long AlbumId { get; set; }
public string Title { get; set; }
public long ArtistId { get; set; }
public virtual Artist Artist { get; set; }
}
the problem with this code is that it keep having the error:
{"SQL logic error or missing database\r\nno such table: Artist"}
and the sqlite file is not being created as well.
does anyone know why and be so kind as to show me how to resolve this?
|
|
|
|
|
I only have very little experience with EF but I think it should look like this in ChinookContext:
public DbSet<Artist> Artists { get; set; }
public DbSet<Album> Albums { get; set; }
Otherwise those properties would have nothing to do with Artist and Album except the plural form of the names
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
In your ChinookContext class, remove the line you have in the OnModelCreating method. You don't need it.
Also, your DbSet lines are bad. They should be:
public DbSet<Artist> Artists { get; set; }
public DbSet<Albums> Albums { get; set; }
I HIGHLY suggest you don't take all of your information on EF from "some tutorial on the web" because you're missing a SH*T TON of information that these tutorials are not tell you. Pick up this book[^]. It's an older book, covering EF4, but it's better than the newer books out there that were released last year.
|
|
|
|
|
please write acode that help me to develop teaching system for kids using java programming language.it include gui.if any one u have any code regarding that send me please.thanks
|
|
|
|
|
No. This isn't rentacoder - if you want something writing then you write it yourself. Also, this is the .NET forum, which has absolutely nothing to do with Java. I suggest, if you're going to try and pretend you know how to code, you learn the basics.
This space for rent
|
|
|
|
|
Greetings to all,
my application runs in a Windows Embedded Compact 7 device and it uses Compact Framework 3.5.
It establishes a TCP connection to a PLC and exchanges data with it.
I open the connection in this way:
mTcpCli = new TcpClient()
mTcpCli.Connect(mIp, mPort);
MBStream = mTcpCli.GetStream();
Then I start the communication thread.
If there is a communication error, I close the connection and I re-open it with the above code.
To close the connection I do ALL this:
MBStream.Close();
MBStream.Dispose();
mTcpCli.Client.Close();
mTcpCli.Close();
((IDisposable)mTcpCli).Dispose();
if (mTcpCli != null)
{
mTcpCli = null;
}
but it seems not to be enough...
Suppose the communication error is cable disconnected, absolutely no way to communicate.
When I re-open the connection the instruction:
mTcpCli.Connect(mIp, mPort);
should give an exception (SocketException) but it doesn't.
Until the communication is interrupted, I could say that it is not a very serious problem because the application tries to communicate with the PLC, it fails and the "close-reopen connection" loop restart (with 10 seconds of pause between one retries).
The true problem is when the communication error is solved: I re-connect the cable.
In this situation the instruction:
mTcpCli.Connect(mIp, mPort);
doesn't give any exception, and should not, but it doesn't establish a connection so the application tries to communicate with the PLC, it fails and retries the connection.
I takes 4-5 attempts to establish a TRUE connection, almost a minute.
I looked for a solution in this and other forum and in MSDN and I found that there is a bug in the TcpClient Close method but the soution, close also the network stream, doesn't work.
I tried to close and dispose all I could with no result.
When I close the connection I need to be sure it is closed and I can't succesfully open it when the cable is disconnected!
Anybody can help me?
Thank you in advance.
Steve
|
|
|
|
|
|
Thank you Richard.
I have modified the code to open the connection in this way:
LingerOption lingerOption = new LingerOption(true, 0);
mTcpCli = new TcpClient();
mTcpCli.LingerState = lingerOption;
mTcpCli.Connect(mIp, mPort);
Unfortunately nothing has changed.
|
|
|
|
|
Sorry, that's the only feature I have ever found that helps in these cases. However, it is possible that the problem lies at the other end of the connection.
|
|
|
|
|
You've tried to help me, I can only thank you even if I have not solved the problem!!
...and now I've learned one more thing!
I don't think that the problem is at the other end of the connection, ie at the PLC, for two reasons: 1- I have disconnected the cable so the PLC can do nothing; 2- there is another touch panel connected to the PLC, a standard HMI, and it works fine with disconnections and re-connections so the PLC seems to behave in the right way.
|
|
|
|
|
Any idea to limit the application google Chrome on Windows?
|
|
|
|
|
|
|
How do you want to limit it? Elaborate more on your objective so people can have a better idea of what you are trying to do?
Limit bandwidth? Limit functionality?
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
bandwidth limit to 0.5 mbps
|
|
|
|
|
I live in an area where the Internet is 1Mbps. It is a slow Internet connection to play games online and play on google chrome youtube simultaneously.
Youtube video load all possible speed, that causes slowness in the online game.
I would like to limit the bandwidth of google chrome to 0.5mps as this runs the online game, and drop velocity when you stop running the online game.
I do not know how to start. Any ideas?
All the ideas are welcome. Thank you,
|
|
|
|
|
Probably the easiest place to start is with a router. You may need another network card:
Limit bandwidth per port - Spiceworks[^]
Or, you may try running YouTube in a virtual machine; you may be able to throttle the virtual internet connection. You need to pick a virtual machine host (Oracle VM; Hyper-V) and have access to an extra OS you can install.
|
|
|
|
|
This really isn't a code problem. You COULD do it but you'd be writing a proxy server. That's an awful lot of work for little gain.
If your artificially limited connection cannot keep up with the playback, YouTube is going to detect the limited bandwidth and automatically go down to a lower resolution to download less data while keeping up with the playback speed. You can get around that by selecting the resolution you want but the playback will pause every few seconds while the player waits for more data.
Seriously, this is solved by not playing YouTube videos while you play the game or by selecting a low resolution playback. It's not solved by writing code.
|
|
|
|
|
Do you want to write/create a solution or do you just want a solution?
If the former then you would need to
1. Learn how IP traffic works
2. Learn how browsers work
3. Learn how to create a server
4. Learn how to work with threads and sockets
5. Learn how to throttle when reading a stream
6. Put the above together to create a proxy server.
If you want the latter then the following worked well for me for limiting bandwidth for a browser. You must however remember to stop it when the throttling is no longer needed.
Charles Web Debugging Proxy • HTTP Monitor / HTTP Proxy / HTTPS & SSL Proxy / Reverse Proxy[^]
|
|
|
|
|
When i bulid my application it showing errror like
Error: " Could Not resolve the com reference 65e121d4-0c60-11d2-a9fc-0000f8754da1 version 2.0. Object refrence not set to an a instance of Object " in vb.net
i do know how to solve this error ?
|
|
|
|
|
Please Edit your question and show the line(s) of code that produces this error, we cannot see your screen from here.
|
|
|
|
|
Actually the code is too big .
errror in Microsoft.Common.Target file
<ResolveComReference
TypeLibNames = " @(CompRefrence) "
.................
........
</ResolveComReference>
|
|
|
|
|