|
|
I have problem. I can' identify my mistake...
int dt = Convert.ToInt32(Items.Rows[T1]["F14"].ToString().Trim());
int mn = Convert.ToInt32(Items.Rows[T1]["F15"].ToString().Trim());
int yr= Convert.ToInt32(Items.Rows[T1]["F16"].ToString().Trim());
string DtString =mn.ToString().Trim() +"/"+ dt.ToString().Trim()+"/"+ yr.ToString().Trim();
DateTime RegExp = Convert.ToDateTime(DtString);
exp_date is datetime field in sqlserver.
string MyDtQry = "UPDATE MyTable SET exp_date='" + RegExp + "' where MyTable.id_no='" + AlmIDNo + "'";
I can't Identify the mistake
Thanks For Ideas
|
|
|
|
|
You have two mistakes
The first is not properly formatting your code as per the posting guidelines.
The second is not saying what errors or difficulties you are encountering.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Paramu1973 wrote:
string MyDtQry = "UPDATE MyTable SET exp_date='" + RegExp + "' where MyTable.id_no='" + AlmIDNo + "'";
In the above statement you need to check what value is being returned by RegExp and that it is in the correct format for both the SQL statement, and your regional date settings. I have a feeling that there are better ways to do this by using SQL parameters which accept DateTime s as values rather than strings.
The best things in life are not things.
|
|
|
|
|
why not use the ctor for DateTime(int year, int month, int day)?
Somthing like:
DateTime dt = new DateTime(yr,mm,dd)
Note that the code above, is written directly in here. Not sure if it will compile but I know that there is such a way to create a DateTime instance.
[add] Also add a parameter. Don't pass the datetime as string(varchar in SQL using '') if the field is datetime in sql.
The same for ID. Don't pass it as string/varchar type if it's int/long.
Something like this:
string MyDtQry = "UPDATE MyTable SET exp_date=@dt where MyTable.id_no=@id";
cmd.Parameters.AddWithVAlue("@dt", RegExp);
cmd.Parameters.AddWithVAlue("@id", AlmIDNo);
All the best,
Dan
modified on Thursday, July 7, 2011 11:55 AM
|
|
|
|
|
1. Instead of going through strings to construct an instance of DateTime , you should use the corresponding constructor: new DateTime(yr, mn, dt)
2. Instead of building a SQL string with embedded values, use parameterized SQL[^]: it makes your code more robust, not to mention considerable performance gains.
|
|
|
|
|
What datatypes are in the table fields? If they're Int32, just cast them. Don't convert to string and right back again.
And don't use the Convert class, it's needless, just use the methods of the datatypes Int32.Parse etc.
You can only pass a DateTime value direectly to SQL with a parameter (which is the right way to do it anyway).
|
|
|
|
|
Try it this way:
DateTime RegExp = new DateTime(0);
try
{
RegExp = new DateTime(yr, mn, dt);
string dateStr = string.Format("{0}/{1}/{2}", yr, mn, dt);
bool parsed = DateTime.TryParse(dateStr, out RegExp);
if (parsed)
{
}
else
{
error
}
}
catch (Exception ex)
{
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I want to create a list/dictionary of all the friendly application names and their executable paths & commands for a specific file type. I've used AssocQueryString but it only returns one instance value.
For example:
The file type ".cs" on my PC has got many application associations for it when I right-click on a ".cs" file and select "Open With->" in the context menu, like "Microsoft Visual Studio 2008" & "Microsoft Visual Studio 2010" & "Notepad" & "Wordpad".
How can I enumerate all these values into a list in C#, obviously it must be extracted from the registry, but I'm very lost in all the "OpenWithList" and "OpenWithProgids" keys..
Thanks
|
|
|
|
|
|
By default selecting an item in a list view with large icon mode makes the selected item thumb grayish.
How to provide thumbnail selection display as in windows explorer?
9ine
|
|
|
|
|
What viewing setting in windows explorer are you referring to? There are five of them in windows xp's explorer.
Ciao,
luker
|
|
|
|
|
When the list view in large icon mode and you hover the mouse over the item thumbnail or select it you will see significant difference with list view of large icons in visual studio.
In visual studio list view when you select item entire thumbnail becomes gray.
I want selected item to look the same as in windows explorer.
9ine
|
|
|
|
|
In my Windows Explorer, there are five viewing modes:
Miniature, Tiles, Symbols, List, Details, in that order.
The only view the selected icon doesn't get some kind of "overlayed" with the selection color is "Miniature". Instead, a frame in selection color is painted around the icon.
This view doesn't seem to be supported by ListView out of the box. But you could
- set View = System.Windows.Forms.View.Tile;
- set TileSize = YourPreferredTileSize;
- Set OwnerDraw = true;
- override OnDrawItem() and draw icons in whichever way you want them to appear.
(Inspired by http://www.tutorials.de/net-windows-forms/307597-c-explorer-listview-mit-miniaturansicht.html)
Ciao,
luker
|
|
|
|
|
hey people,
i still have a problem about how to moove from a DataTable full with csv Value to a multi-line chart.
The fact is,in my DataTable,i have many value of censor(in °C,KWh,Mwh..)and i want to represent for each censor value a multi-line chart,with Date and time in X Axis,and with two Y axis the Legend and value of censor.
i joined a sample of csv to fell my DataTable
that is the part of my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.VisualBasic;
using System.Globalization;
using System.Drawing.Drawing2D;
using ZedGraph;
using System.Linq;
using System.Windows.Forms.Integration;
public DataTable BuildDataTable(string fileFullPath, char seperator)
{
const int EOF = -1;
DataTable myTable = new DataTable("MyTable");
DataRow myRow;
StreamReader myReader = new StreamReader(fileFullPath);
string Set_Data = myReader.ReadLine();
int Set_len = Set_Data.Length;
try
{
myReader = new StreamReader(fileFullPath);
}
catch (Exception ex)
{
MessageBox.Show("Fout bij openen bestand: " + ex.Message);
return new DataTable("Empty");
}
try
{
string[] fieldValues = new string[Set_len];
fieldValues = myReader.ReadLine().Split(new Char[] { seperator, '\t', });
for (int i = 0; i < fieldValues.Length; i++)
{
myTable.Columns.Add(new DataColumn(fieldValues[i].ToString().Trim()));
}
while (myReader.Peek() != EOF)
{
fieldValues = myReader.ReadLine().Split(new Char[] { seperator, '\t' });
myRow = myTable.NewRow();
for (int i = 0; i < fieldValues.Length; i++)
{
myRow[i] = fieldValues[i].ToString().Trim();
}
myTable.Rows.Add(myRow);
}
}
catch (Exception ex)
{
MessageBox.Show("Error building datatable: " + ex.Message);
return new DataTable("Empty");
}
finally
{
if (myReader != null)
{
myReader.Close();
}
}
myTable.AcceptChanges();
if (myReader != null)
{
myReader.Close();
}
dataGridView1.DataSource = myTable;
return myTable;
}
public void Proces_File()
{
char[] Separator = { ';', ':' };
String Choose_File;
DataTable DT;
OpenFD.InitialDirectory = "Y:\\";
OpenFD.Filter = "txt files(*.txt)|*.txt|All Files(*.*)|*.*";
OpenFD.FilterIndex = 2;
OpenFD.RestoreDirectory = true;
if (OpenFD.ShowDialog() != DialogResult.Cancel)
{
Choose_File = OpenFD.FileName;
richTextBox1.LoadFile(Choose_File, RichTextBoxStreamType.PlainText);
DT = BuildDataTable(OpenFD.FileName, ';');
this.dataGridView1.DataSource = DT;
}
private void button3_Click(object sender, EventArgs e)
{
Proces_File();
}
thx in advance
|
|
|
|
|
What is your problem? There is no graph related code in that sample at all.
|
|
|
|
|
That is my Problem,a want to get vlue in my DataTAble als Point for a multi line chart,but i don´t know how to do it
|
|
|
|
|
So basically you want someone to solve your entire problem for you? That's not how CodeProject works. Go away and read the documentation for the chart control you are trying to use (looks like ZedGraph) and work out how to do it. And learn how to type while you're at it ... a typo here or there will happen but your posts read like you just don't care.
|
|
|
|
|
don´t misinterpret the way i try to expose my Problem, i am not looking for somebody who can make the work for me,but i am here because i hope that may be somebody can have the answer of my unsolved questions by the way you (may be not ) so about the use a Zedgraph i have a powerful documentation,and i try to make practicaly sample to understand Functionment of that tools
hier is a part of my code where i take the values(contain) in a DataTable in a List and try to Buuild Point for my Chart,just look about it please and tell me what is wrong.
thx
public void ADD_Chart_Style( ZedGraphControl ZGC, DataTable My_DT)
{
Graphics G= this.CreateGraphics() ;
DataRow Dat_Row;
DataColumn Dat_Colm;
int Index = 0;
List<DateTime> XDate = new List<DateTime>();
List<double> Value = new List<double>();
List<DataRow> My_Ro_List = new List<DataRow>();
foreach (DataRow My_DT_Rows in My_DT.Rows)
{
My_Ro_List.Add(My_DT_Rows);
foreach (var item in My_DT_Rows.ItemArray)
Value.Add(Convert.ToDouble(item));
}
String Temp = "Date";
var Result = My_DT.AsEnumerable();
foreach (var result in My_DT.Columns)
{
XDate.Add(Convert.ToDateTime(My_DT.Columns.IndexOf("Date")));
}
List<DataColumn> My_C_List = new List<DataColumn>();
foreach (DataColumn MY_DT_COL in My_DT.Columns)
{
My_C_List.Add(MY_DT_COL);
}
int len = My_DT.Columns.IndexOf("Date");
DateTime[] X_ValData = new DateTime[len];
PointPairList List1 = new PointPairList();
for (int i = 0; i < My_DT.Rows.Count; i++)
{
List1.Add(Convert.ToDouble(XDate[i]), Convert.ToDouble(Value));
X_ValData[i] = XDate[i];
for (int j = 0; j < My_DT.Columns.Count; j++)
{
ZGC.MasterPane.PaneList.Clear();
GraphPane My_pane = new GraphPane();
My_pane.CurveList.Clear();
My_pane.GraphObjList.Clear();
ZGC.GraphPane = My_pane;
My_pane.Title.Text = "Auswerte Software Version 1.0";
My_pane.Title.FontSpec.Size = 14;
My_pane.XAxis.Title.Text = "DATE/Hour/Minutes";
My_pane.YAxis.Title.Text = "Value";
My_pane.Fill = new Fill(Color.White, Color.FromArgb(220,220,255),45F);
LineItem My_Curve = new LineItem("" , List1 , Color.DarkBlue , SymbolType.Diamond);
My_Curve.Symbol.Size = 6;
My_Curve.Symbol.Fill.Color = Color.DarkBlue;
My_Curve.Symbol.Fill.IsVisible = true;
My_Curve.Line.IsVisible = false;
My_pane.CurveList.Add(My_Curve);
My_pane.AxisChange();
}
using (Graphics g = this.CreateGraphics())
{
ZGC.MasterPane.ReSize(g, ZGC.MasterPane.Rect);
}
ZGC.Invalidate();
in my Form this
ZedGraphControl My_ZGC = new ZedGraphControl();
private void Form1_Load(object sender, EventArgs e)
{
string Use_Path = OpenFD.FileName;
DataTable MY_D = new DataTable();
MY_D = BuildDataTable( Use_Path, ';');
Cs.ADD_Chart_Style( My_ZGC, MY_D);
}
public void Set_SiZe()
{
My_ZGC.Location = new Point(10,10);
My_ZGC.Size = new Size(this.ClientRectangle.Width - 20,this.ClientRectangle.Height - 20);
}
public void Graph_load()
{
Form new_F = new Form();
new_F.Controls.Add(My_ZGC);
new_F.ShowDialog();
}
|
|
|
|
|
did someboy have a answer of my question please????
|
|
|
|
|
Hi,
Kindly let me know that, How may I get the name of Windows Operation system using C#?
Actually I want to know that, what windows is being used.
Example:
Windows XP
or
Windows Server 2003
or
Windows Server 2008
or
Windows Vista
or
Windows 7
Thank you
(Riaz)
|
|
|
|
|
You need to use the OSVersion Property of the System.Environment Class. Here is an MSDN article on how to do it How to determine the Windows version by using Visual C#[^]. (Hint - it was the first hit in a Google search).
Hope this helps
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
|
Good Evening All
i have a Function in my DataLayer that is defined like this
public bool SynchProductsCategoryToCBD(IList<EcashProductCatModel> model)
{
con = new SqlConnection(strCon);
cmdinsert = new SqlCommand("sp_AddProductCategory");
cmdinsert.CommandType = CommandType.StoredProcedure;
cmdinsert.Connection = con;
bool Error = false;
try
{
con.Open();
foreach (EcashProductCatModel ecash in model)
{
cmdinsert.Parameters.Add("@CATEGORY_ID", SqlDbType.Int).Value = ecash.CATEGORY_ID;
cmdinsert.Parameters.Add("@CATEGORY_DESCRIPTION", SqlDbType.VarChar).Value = ecash.CATEGORY_DESCRIPTION;
cmdinsert.Parameters.Add("@SCHOOLID", SqlDbType.Int).Value = ecash.SCHOOLID;
cmdinsert.ExecuteNonQuery();
}
Error = true;
}
catch (Exception ex)
{
Logger.LoggerClient logger = new Logger.LoggerClient();
Logger.LoggerModel models = new Logger.LoggerModel();
models.iTYPEID = Convert.ToInt32(GenericEnum.Logging_Type.ECASH_SYCH);
models.sLOGGER_CLASS = "eCashDatalayer";
models.sLOGGER_DESCRIPTION = ex.Message;
models.sLOGGER_FUNCTION = "SynchProductsCategoryToCBD";
models.sLOGGER_LOGGEDINUSERID = "";
models.sLOGGER_PAGE = "NA";
models.sLOGGER_VALUE = "NA";
logger.LogIncident(models);
}
finally
{
con.Close();
}
return Error;
}
and i pass the List of objects, i have inspected the list and it contains valid values and i had 13 records , but in the database i get only 1 record
What is it that i am doing wrong ?
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Well, one thing you're doing wrong is that you fail to clear the SqlCommand.Parameters collection between stored proc calls. Just add this line at the top of your foreach loop:
cmdInsert.Parameters.Clear();
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|