|
Hi, all....
I am trying to execute the code below, but returns error due to date comparison :
<pre0>
cmd.CommandText = @"update TabFx set Date_xyz= @fer, Descrip=@descr where Date_xyz=" + Convert.ToDateTime(DataGridView1.SelectedRows[0].Cells[0].Value)
cmd.Parameters.AddWithValue("@fer", Convert.ToDateTime(DGV1.SelectedRows[0].Cells[0].Value));
cmd.Parameters.AddWithValue("@descr", DataGridView1.SelectedRows[0].Cells[1].Value);
cmd.ExecuteNonQuery();
Date_xyz is as field type DateTime in a MSAccess Table
How can I do this compare?
Thanks in advance!
|
|
|
|
|
Hi,
you are using a mix of parameter substitution (which is good) and direct string concatenation (which is bad).
When concatenating (which is bad) SQL expects dates or datetimes in a specific format and inside quotes.
Why don't you use AddWithValue() for the date as well?
Some examples[^]
|
|
|
|
|
Thanks for reply Luc...but the problem happens in the SQL command, when compare the field data (from the database) with the DataGridView cell that contains a date (sorry for the bad English...)...it returns error : "Wrong data type in criteria"
I don't know how to write the comparison...
the line is :
cmd.CommandText = @"update TabFx set Ferx =@fer, Descrip=@descr where Ferx="
+ Convert.ToDateTime(DGV1.SelectedRows[0].Cells[0].Value);
|
|
|
|
|
You can use a parameter in the WHERE part of your SQL statement just like you do in the SET part, so it could look like
CommandText = "... WHERE Ferx=@Ferx";
...
cmd.Parameters.AddWithValue("@Ferx", Convert.ToDateTime(DataGridView1.SelectedRows[0].Cells[0].Value));
Warning: IIRC you must provide the parameters (i.e. the calls to AddWithValue and the like) in the same order as the parameters appear in your SQL statement, since OleDb+Access does not really care about the parameter names!
|
|
|
|
|
ok Luc...I used your tip and it Works....thank you very much for the help
|
|
|
|
|
you're welcome
|
|
|
|
|
|
Thank you Richard for the reading suggestion....I'll be Reading this....
|
|
|
|
|
Hi All,
I have a WinSCP Directory and have files in it. I need to get the date as 01_MMM (MMM represents the current month example- 01_APR and for May it should return 01_MAY so on and so forth) and I need to append this string '01_MMM' to the name of the file.
Please let me know how can I achieve that using C# Only.
Thanks,
Sriram
|
|
|
|
|
The System.IO namespace has lots of classes which you can use. There is some code as a good starting point here, list - Getting all file names from a folder using C# - Stack Overflow[^].
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Thank you for your response but this is not in the regular windows directory. This directory is a remote path. I am connecting to this WinSCP directory by giving hostname,username and password.
EnumerateRemoteFiles is what I am using to read the file names but I am unable to find a function to rename them in remote directory.
|
|
|
|
|
Sriram Valluri wrote: WinSCP directory
I think what you mean then is that it is an ftp directory. Just google how to rename ftp files via c#.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
|
below is my code.
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "ap*****",
UserName = "****",
Password = "******",
SshHostKeyFingerprint = "*******"
};
using (Session session = new Session())
{
session.ExecutablePath = @"WinSCP.exe path";
session.Open(sessionOptions);
List<RemoteFileInfo> files =
session.EnumerateRemoteFiles(
MonitorDirectory, FileSearchPattern, EnumerationOptions.None)
.ToList();
DateTime now = DateTime.Today;
ReportMonth = now.ToString("MMM").ToUpper();
foreach (RemoteFileInfo fileInfo in files)
{
------------------------------have to do renaming of the file here---------------------------
if (fileInfo.FullName.Contains(GetClientID))
{
if (fileInfo.Length > ThresholdValue)
{
FileModifiedDate = fileInfo.LastWriteTime.ToString("yyyyMM", CultureInfo.InvariantCulture);
if (GetReportDateYM == FileModifiedDate || fileInfo.FullName.Contains(ReportMonth))
{
FileName = fileInfo.FullName;
Dts.Variables["User::FileName"].Value = FileName;
Dts.Variables["User::FileDate"].Value = FileModifiedDate;
Dts.TaskResult = (int)ScriptResults.Success;
break;
}
}
}
So here I have a directory in remote server and I am accessing it through WinSCP tool. requirement is to rename the files insider this remote directory. I can read each and every file name but I am not able to find rename function here.
|
|
|
|
|
Hi,
I have no experience with WinSCP, however browsing the documentation I'm now convinced what you need is here[^].
Google is your friend, treat him well.
|
|
|
|
|
Thank you Luc Pattyn. will go through the same.
|
|
|
|
|
Dear all,
I am sorry by now, I want to use Multicombobox in datagridview,
I have access file have two table :ItemAll, Pur in acccess file.Column Items in datagridview1 is Combobox,
1- I want to create column of items as multicombobox ,when click on culumn Items , its doplist table ItemAll have two column :Items,NameItem.
2-In datagridview , when click multicombobox anh selcect Items column in combobox , In columm datagridview will receive data .
I have added Multicombobox.cs, MulticomboboxPopup in project, I use dataset ACCSDataset.
Thank you
My email:[DELETED]@gmail.com
modified 27-Apr-20 1:25am.
|
|
|
|
|
Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am programing and application for work which requires a certain level of access rights to users. Once logged in I get the access level number 1-10 which is then put onto a splash screen in a hidden txt box.
on the closure of the splash screen i would like it to go to a menu for that access right.
This is the code I am using
private void tmr_splash_Tick(object sender, EventArgs e)
{
prb_splash.Increment(1);
if (prb_splash.Value == 100)
tmr_splash.Stop();
if (prb_splash.Value == 100)
this.Hide();
if (prb_splash.Value == 100 & (!txt_number.Text.Contains("10")))
{
frm_Artemis_admin aa = new frm_Artemis_admin();
aa.ShowDialog();
}
else
if (prb_splash.Value == 100 & (!txt_number.Text.Contains("09")))
{
frm_Employees_edit aa = new frm_Employees_edit();
aa.ShowDialog();
}
The application runs but even though I have changed the access rights to 9 to test it its still going to the admin menu?
If anyone can help that would be great.
Many Thanks :)
|
|
|
|
|
This is going to be dependent on data to a large degree - and we don't have any access to that.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
"9" is not the same as "09" when searching a text string.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
This is way too simplistic, you need to build up a framework for managing your security.
Your users credentials and rights (0-9) need to be stored in a class that all your forms can access.
When you instantiate a form you need to be able to check that class and apply the restrictions to the form as it is constructed (in WPF by binding the enable/visible values).
Instead of 10 levels the standard is to use Roles where a user may have multiple roles.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Hi,
I'm trying to solve 100 doors Kata from provided link "http://www.tddbuddy.com/katas/100%20Doors.pdf[^]"
I've solved Open and Closed door status but stuck with Bonus part where I have to show Holding state as well. Can someone please help me to solve that. Below is the code for Open and Close door.
List<bool> listDoorStatus= new List<bool>();
for (int i = 1; i <= 100; i++)
{
for (int j = i; j <= numberOfDoors; j += i)
{
listDoorStatus[j - 1] = !listDoorStatus[j - 1];
}
}
StringBuilder sb = new StringBuilder();
foreach (var item in listDoorStatus)
{
if (item)
{
sb.Append("@");
}
else
{
sb.Append("#");
}
} return sb.toString()
|
|
|
|
|
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am able to solve till two status of doors which are open and close. but in next step have to Add a third state which is holding (use H). By adding this state, you must toggle between open, holding and closed when visiting the doors.
I am just trying to learn this kind of problems which we generally found on Hacker Rank just like FizzBuzz.
So Till now what I solved:
If pass=1 for 10 doors then output will be @@@@@@@@@@
If Pass=2 for 10 doors then output will be @#@#@#@#@#
If Pass=3 for 10 doors then output will be @###@@@###
Where @ represents Open, and # represents close.
till this place I have solved it. But not when I've to show holding status as well. i am bit confused. I tried to create a loop on output and place H (represent Holding State) but it didn't work for me.
Like for Pass 2 output should be @H#@H#@H#@
|
|
|
|