|
Hi all, I am trying to insert data into sqlite datetime, but it seems like making my life really deficult.
this is what I have done to do this;
con.Open();<br />
cmd = new SQLiteCommand();<br />
cmd = con.CreateCommand();<br />
cmd.Connection = con;<br />
cmd.CommandText = " INSERT INTO Hall_Call_Up (Call,Time) VALUES ('1','" + dateTime.Now.ToString("YYYY-MM-DD HH:MM:SS") + "')";<br />
cmd.ExecuteNonQuery();
this is giving me error saying "Unable to read data"
But if I connect to datagridview and I do this;
this.hall_Call_UpTableAdapter.Insert(1, DateTime.Now);
it is working.
Can some one please help me.
thanks
|
|
|
|
|
Use a parameterised query and pass in a DateTime.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
hi Christian Graus,
Sorry for delay. I am very very new to database. infact this is for the first time I need to use database i any of my application. Do you mind to help me little more by showing how it should be done. I appolize if I am asking too much.
this is how[] the SQLite is telling me to do. Since I have never used it I don't know honeslty speaking.
thanks again.
|
|
|
|
|
The string your using will create an incorrect and unparseable DateTime string (read the MS docs for the correct DateTime templates).
The template you DO want is this: "yyyy-MM-dd HH:mm:ss".
|
|
|
|
|
I am doing a speech recognition project for amharic ( Ethiopian) language. and i want to use sapi.Is there any interface used to extract the recognized phenomes; not the final recognized words...
tnx
modified on Wednesday, November 11, 2009 2:06 PM
|
|
|
|
|
Am working on a Software, Does anyone have an idea on Socket programming?.. i need to capture the wireless port of my laptop using C# code.. Pls help out Cheers!!
|
|
|
|
|
|
hello all...
i have logical trouble in my windows application
there is one eventHandler (Button1_click)
contains
two sqlcommands
the first sqlcommand insert into parent table (primary key table)
the second sqlcommand insert into references table
as expected the code generate sql exception because the referial constraint
the question is : how to solve this problem without adding new eventHandler and without modifying the tables relation?
best regards
|
|
|
|
|
You have to return the newly created ID's from the first insert and update your data before sending the second insert.
A better solution may be to parcel the whole data set up as xml, pass it into a stored procedure, then you can process the whole lot in one shot.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
The application shouldn't know or care about the details; all that should be handled in the Data Access Layer.
|
|
|
|
|
Hi every Body.
please tell me why do you we use cookie and session in web site?
thank you.
|
|
|
|
|
Cookies are used to persist data on the client so that it can be reused by your web page when it is next loaded. Session variable are similar, but on the server end. However as these are linked to a particular session ID they will go away after a bit when the client leaves your web site as they are stored in memory. However, cookies are saved to disk, and may be deleted by the end user.
Many sites do not use either, and don't need to.
It all depends what you want to do, and how you want your web app to work.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
|
hi,
i have to restore a java window that is minimized in systray (process is: javaw.exe) and not shown in the taskbar.
i get the processid by process.getprocess but the mainwindowhandle is 0 if the window is minimized.
does anyone knows how i can get the main window handle? the window title is known.
thank you.
|
|
|
|
|
I think the window is closed at this moment.
Can't you send a message to the process?
|
|
|
|
|
now i can get the handle by form caption (GetWindowByCaption) but it looks frozen (no repaint, the textboxes are complety missing). but it seems i am able to set the needed values.
thanks for ur help!
|
|
|
|
|
|
I have a new windows application project using C# and I make setup project.
In the windows application project I have MDIParent as Main Form and i write this code to change the language from English to Arabic:
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ar-EG");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-EG");
this.Controls.Clear();
this.InitializeComponent();
this method is fine when i run the application.
but when i install the setup project this method not change any thing.
i need help about this problem.
thanks
wael salem
|
|
|
|
|
I'm having trouble implementing a depth chart for my football simulator program. The way my program is structured, I have a Player class, a Team class, and a League class--the core classes. The depthchart would group players by their position and, by each position, sort by OVR (integer) in descending order (but only if their injury status is "false"--governed by a CanPlay method in my Player class; otherwise, they are not eligible for the depthchart). Position is a PlayerPosition type and PlayerPosition is enumerated as such:
[code]
public enum PlayerPosition { QB, HB, WR, TE, LT, LG, C, RG, RT, DE, DT, OLB, MLB, CB, FS, SS }
[/code]
This is in my Team class:
[code]
public List<Player> depthChart { get; set; }
public List<Player>[] DepthChart
{
get
{
var result = new List<Player>[Enum.GetValues(typeof(PlayerPosition)).Length];
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
result[(int)pos] = this.Players.Where(pl => pl.position == pos && pl.CanPlay).OrderByDescending(pl => pl.OVR).ToList();
}
return result;
}
[/code]
These are in my Main() method: two attempts to obtain information from the depth chart.
Method 1:
[code]
Team t = league.Teams[0];
var depthChart = t.DepthChart;
Console.WriteLine(depthChart);
[/code]
Method 2:
[code]
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
Console.Write(pos.ToString() + ':');
depthChart[(int)pos].ForEach(p => Console.Write(' ' + p.lastName));
Console.WriteLine();
}
[/code]
For method 1, I get on the console readout: System.Collections.Generic.List`1[FranchiseSim.Player][]
For method 2, I get on the console readout only the proper position strings (like QB, RB, etc.) and the colon ( but nothing from the depth chart.
|
|
|
|
|
First, a direct answer to your questions:
Method 1
var depthChart = t.DepthChart;
Console.WriteLine(depthChart);
depthChart will be a List<Player> so the .ToString() method will just return the typename of the depthChart . To get the player roster you need to iterate over the list and get output each player individually. You should put a method in your Team class (NOT in the main method- bad encapsulation).
Method 2
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
Console.Write(pos.ToString() + ':');
depthChart[(int)pos].ForEach(p => Console.Write(' ' + p.lastName));
Console.WriteLine();
}
Is more complicated. The position of a type of player in the depth chart doesn't correspond to the position in the depthChart list, unless you ONLY add them in the order they appear in the enum. To do so would be very bad design. If (and only if) you have one player per position, you could consider a Dictionary<PlayerPosition, Player> Though even this is messy.
Now for the hard part, I think the overall design of the above is wrong. Some people will disagree with me, others will (hopefully) agree you can wrapper all the following up in <IMO> tags if you like . There is debate about the use of enums . I fall into the camp that they are [mostly] evil. The prescence of enums normally indicates a lack of polymorphism that should be expressed. In your case I think you should have something like the following:
public Interface IPlayer
{
string Surname {get; set;}
string PositionName { get; }
}
public abstract class Player : IPlayer
{
public string Surname {get; set;}
public string PositionName { get; protected set; }
}
public class QuaterBack : Player
{
public QuaterBack()
{
PositionName = "Quater Back";
}
}
public class WideReciever : Player
{
public QuaterBack()
{
PositionName = "Wide Reciever";
}
}
public interface ITeam
{
List<IPlayer> Players {get; }
}
public class Team : ITeam
{
public List<IPlayer> Players {get; private set}
public string TeamRoster()
{
string roster = "";
Players.ForEach( p=> roster += p.PositionName + ": " + p.Surname + " ");
return roster;
}
public Team()
{
Players = new List<IPlayer>();
}
}
The big question should now be why bother? Functionality is now encapsulated in the correct place, Player handles whatever the player does,Team will handle team-level stuff. Also, you can add extra properties to Player , for example a Positional Shortcode e.g. ("QB"), in the original implementation you would have to keep a dictionary for such information (and any other information relating to the position. Additionally The above can be made to demonstrate polymorhpism: As an example, let's say only Quaterbacks are allowed to kick off (I don't know enough about American football for a real example), you can add a KickOff method to a Quaterback without implementing it for any of the other player types. Not only that, but long enums often lead to messy switch statements (or long lists of if s), giving off a rank code-smell as they go.
The code I've given isn't perfect (I haven't thought about it very deeply), but hopefully will provide a starting point. For example, I think there really should be a IPlayerType interface subclassed by PlayerType type inherted per position (e.g. QuaterBack ), and the Player should expose a property of IPlayerType , rather than BE a QuaterBack or LineBack or whatever. This will allow the player to change position easily and encapsultes the position properly, against the player.
Take a look at for some started WRT enums:
http://devpinoy.org/blogs/cruizer/archive/2007/09/12/enums-are-evil.aspx[^]
and http://www.colourcoding.net/Blog/archive/2009/07/25/enums-are-evil-the-state-pattern.aspx[^]
One of the problems in describing the reason why you shouldn't use enums is that they work when starting out writing a class (so any explanation of why not to use them seems longer/harder than the original), but as the class develops the shortfalls start to appear.
Hope this helps!
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Thank you for your response. I've considered your ideas and it occurred to me that maybe all of this isn't necessary afterall; perhaps, for each team, I could simply list each position with each player at that position in descending order by OVR with simple loops.
This is in my Main() method
foreach (Team t in league.Teams)
{
Console.WriteLine("");
Console.WriteLine(t.Name + " " + t.Nickname);
foreach (PlayerPosition pos in Enum.GetValues(typeof(PlayerPosition)))
{
Console.WriteLine(pos);
league.AllPlayers.Where(pl => pl.position == pos).OrderByDescending(pl => pl.OVR).ToList().ForEach(pl => pl.Print());
}
}
The only problem with this code is that for each team displayed, it's putting ALL of the players in the league, regardless of what team they're on, in each team's roster that is displayed.
I believe has to do with the AllPlayers designation. This is located in my League class:
public List<Player> AllPlayers
{
get
{
var list = from t in Teams
from p in t.Players
select p;
return list.ToList();
}
}
How would you suggest I fix this?
|
|
|
|
|
This idea is not good from a from an oo point of view. It is important to encapsulate your classes properly.
You have a need for a team class, it should be responsible for maintaining it's own list of players. Likewise each player must maintain it's own information (e.g. Name, Position etc).
I suggest you try my example. To get the list of players in a particular position, you would just have to loop around each team, then loop each roster looking for players of the type required.
I also suggest you find a good OO book and learn the basic principles. If you are using an OO language like C#, learning OO principles will make coding easier for you, and the code you will produce will be neater and easier to maintain and understand. It is difficult to make the mental shift from procedure to object oriented programming, but doing so will make your life easier when using c# and is well worth the effort.
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
I have a winform with two texboxes, one below the other.
When i resize horizontal there is no problem, but when i want to resize vertical only can resize one and i need to resize both proportionally.
Already tryed many anchor property configurations without luck...
Any idea?
Thanks in advance.
|
|
|
|
|
Hi,
I was thinking about Anchor property as well. How about using a SplitContainer in a horizontal oritation, with two textBoxes Dock property set as Fill?
Br!"
Sun
|
|
|
|
|
You suggestion not soove my needs... each texbox is on different groupbox...
|
|
|
|