|
That worked but if no record is found for someone can I just skip it and continue? Your revised sql does exactly what I wanted to do except it gives an error and the users wouldn't know what to do with it. The problem is that we have some employee that are suppliers and others direct and vise versa. this is what I am getting.
No staff tracking record found for resource 'ALISON GREEN'.
Cannot insert the value NULL into column 'StaffTrackingID', table 'SP2010_EDCStaffing_AppDB.dbo.StaffTrackingFTEData'; column does not allow nulls. INSERT fails.
The statement has been terminated.
The Field in StaffTracking to determine if a person is a direct or Supplier is PersonnelResourceType. I changed the above code to include in the where clause SELECT @StaffTrackingID = ID FROM StaffTracking WHERE CATWResourceName = @Name and PersonnelResourceType = 'Supplier'; but still getting that message.
modified 29-Jun-15 10:51am.
|
|
|
|
|
const string Query = @"DECLARE @StaffTrackingID int;
SELECT @StaffTrackingID = ID FROM StaffTracking WHERE CATWResourceName = @Name;
If @@ROWCOUNT != 0 And NOT EXISTS (SELECT 1 FROM StaffTrackingFTEData WHERE StaffTrackingID = @StaffTrackingID And Period = @Period)
INSERT INTO StaffTrackingFTEData ([StaffTrackingID], [EstimateHours], [EstimateFTE], [ActualHours], [ActualFTE],[Comment], [CommentBy], [Period])
VALUES (@StaffTrackingID, @Estimatehours, @EstimateFTE, @ActualHours, @ActualFTE, @Comment, @CommentBy, @Period)
";
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks that worked. Really appreciated it.
|
|
|
|
|
Don't Clear and re-Add the Parameters for each row; just set the Values.
|
|
|
|
|
Thanks. Just set the values beforehand?
|
|
|
|
|
No - create the SqlParameters just once, before the foreach-loop and capture them in variables. Then inside the foreach-loop assign new values to these instead of recreating new SqlParameters for each loop-iteration.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Can you provide a snippet of what you are talking about?
So this is not correct?
<pre lang="c#"> protected void SubmitButton_Click(object sender, EventArgs e)
{
const string Query = "INSERT INTO StaffTrackingFTEData ([StaffTrackingID], [EstimateHours], [EstimateFTE], [ActualHours], [ActualFTE],[Comment], [CommentBy], [Period]) VALUES ((Select StaffTracking.ID From StaffTracking where StaffTracking.CATWResourceName = @Name), @Estimatehours, @EstimateFTE, @ActualHours, @ActualFTE, @Comment, @CommentBy, @Period)";
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString);
using (SqlCommand command = new SqlCommand(Query, conn))
{
conn.Open();
command.Parameters.AddWithValue("@StaffTrackingID", SqlDbType.Int).Direction = ParameterDirection.Output;
foreach (GridViewRow row in gvCATW.Rows)
{
command.Parameters.AddWithValue("@Name", ((TextBox)row.FindControl("txtName")).Text);
.....
.....
.....
|
|
|
|
|
|
Hi, I'm having trouble with the following code which takes a file on my local hard drive and writes it to a Linux server via FTP. It works, however the permissions of the file after it has been written to the server is 000 and I would like permission set to 775. Any ideas? The source file on my local hard drive is first created with the StreamWriter object.
string fileUri = "ftp://" + serverAddressTextBox.Text + "/" + masterDirectoryFileName;
DeleteFileOnServer(fileUri);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(fileUri);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(ftpUserNameTextBox.Text, ftpPasswordTextBox.Text);
StreamReader sourceStream = new StreamReader(directoryPath + "\\" + masterDirectoryFileName);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
richTextBox2.Text += "Upload File Complete, status {0}" + response.StatusDescription;
response.Close();
Thanks for any insight you can provide!
|
|
|
|
|
You can't do it directly via the .NET FTP command. What you will have to do is work around this using something like this:
[DllImport("wininet.dll")]
private extern static IntPtr InternetConnect(IntPtr internet, string host, short port, string username, string password, int service, int flags, IntPtr context);
[DllImport("wininet.dll")]
private extern static bool FtpCommand(IntPtr connect, bool expectResponse, int flags, string command, IntPtr context, out IntPtr ftpCommand);
[DllImport("wininet.dll")]
private extern static bool IntPtr InternetCloseHandle(IntPtr connect);
public static bool ChangePermission(string uri, string folder, string userName, string password)
{
IntPtr context = IntPtr.Zero;
IntPtr ftpCommand = IntPtr.Zero;
IntPtr open = InternetOpen("Portal", 1, null, null, 0x10000000);
IntPtr connected = InternetConnect(open, uri, 21, userName, password, 1, 0x08000000, context);
if (!FtpCommand(connected, false, 0x00000001, "CWD " + folder, context, out ftpCommand)) return false;
if (!FtpCommand(connected, false, 0x00000001, "SITE CHMOD 775 theFile.txt", context, out ftpCommand)) return false;
bool connectedclose = InternetCloseHandle(connected);
bool openclose = InternetCloseHandle(open);
return (connectedclose && openclose)
} Note that I've just typed this out into the editor here. There may be a minor syntax error or two, but this should give you the idea.
|
|
|
|
|
Awesome, Thanks! I'll give it a go and report back. It looks like I'll need to bring in the InternetOpen procedure from wininet.dll as well.
|
|
|
|
|
No success yet. With the following code ChangePermission returns a false value every time. The file I'm adjusting permissions for is located in the root directory. I'm kind of learning as I go so there's a good chance I missed something obvious.
[DllImport("wininet.dll")]
private extern static IntPtr InternetConnect(IntPtr internet, string host, short port, string username, string password, int service, int flags, IntPtr context);
[DllImport("wininet.dll")]
private extern static bool FtpCommand(IntPtr connect, bool expectResponse, int flags, string command, IntPtr context, out IntPtr ftpCommand);
[DllImport("wininet.dll")]
private extern static bool InternetCloseHandle(IntPtr connect);
[DllImport("wininet.dll")]
static extern IntPtr InternetOpen(string lpszAgent, int dwAccessType, string lpszProxyName, string lpszProxyBypass, int dwFlags);
public static bool ChangePermission(string uri, string userName, string password, string fileName)
{
IntPtr context = IntPtr.Zero;
IntPtr ftpCommand = IntPtr.Zero;
IntPtr open = InternetOpen("Portal", 1, null, null, 0x10000000);
IntPtr connected = InternetConnect(open, uri, 21, userName, password, 1, 0x08000000, context);
if (!FtpCommand(connected, false, 0x00000001, "SITE CHMOD 775 " + fileName, context, out ftpCommand)) return false;
bool connectedclose = InternetCloseHandle(connected);
bool openclose = InternetCloseHandle(open);
return (connectedclose && openclose);
}
.
.
.
if (!ChangePermission("ftp://" + serverAddressTextBox.Text, ftpUserNameTextBox.Text, ftpPasswordTextBox.Text, masterDirectoryFileName))
richTextBox1.Text = "Permissions adjustment failed";
|
|
|
|
|
This project[^] may be of use. It has support for more FTP stuff than the .NET Framework.
I have used it successfully myself.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
There is only problem which is about the input string was not in the correct format. I use a textbox1 which is for me to type a number in the string format as I store the string in a variable knn. Then I try to convert it to Int32 and store it in another variable wup. However, after I tried to run the program, the error of input string popped up and I really run out of idea on what to do next.
public void find() {
int a = 0;
int h = 0;
Int32 t = 1;
int f = 130;
int d = 230;
string knn;
Int32 wup = 0;
knn = textBox1.Text;
wup = Convert.ToInt32(knn);
int [,] yes=new int[10,10];
for(a=0 ;a<=7 ; a++) {
for (h = 0; h <= 7; h++)
{
if (a == 0)
{
if( t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 0 && h == 7)
{
f = 130;
d = d + 20;
}
if (a == 1)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 1 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 2)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index"+ Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
textBox4.Text = textBox4.Text + Environment.NewLine + "y= " + (Convert.ToString(h));
}
f = f + 20;
}
if (a == 2 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 3)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text = "Index" + Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
}
f = f + 20;
}
if (a == 3 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 4)
{
if (t == wup){
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 4 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 5)
{
if (t == wup){
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index"+ Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
}
f = f + 20;
}
yes[a, h] = t;
t++;
if (a == 5 && h == 7)
{
break;
}
}
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
}
}
modified 25-Jun-15 11:55am.
|
|
|
|
|
If you enter a none-integer value in your TextBox, Convert.ToInt32 is going to fail. In cases of parsing values, you really should use the appropriate TryParse instead, so you would expect this to be something like
int value;
if (!int.TryParse(myStringValue, out value))
{
return;
}
|
|
|
|
|
I am still unsure about what you commented. So I just need to insert this chunk into my code? In addition, int value represents which variable of mine? I am actually quite new to programming so please help me.
|
|
|
|
|
Remove the lines
knn = textBox1.Text;
wup = Convert.ToInt32(knn); and replace with
if (!int.TryParse(textBox1.Text, out wup))
{
MessageBox.Show("Please enter an integer value");
return;
}
Some other points ... instead of using
textBox2.Text = "Index = " + Convert.ToString(t); you can use the built-in ToString() method e.g.
textBox2.Text = "Index = " + t.ToString(); or possibly even better
textBox2.Text = String.Format("Index = {0}", t); There is more tidying up you could do but I'll leave it there
|
|
|
|
|
hi
Does anyone experienced in the text-to-speech in C# WinForm ?
Is it possible to get a clue or direction ?
thanks
|
|
|
|
|
Have you tried searching the articles[^] or even Google. They will give you a clue and an example you can work through.
The forums are for asking specific question or starting a discussion use the articles for research.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
goldsoft wrote: Is it possible to get a clue "MS Agent"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am trying to make and Android app with ASP.NET WebService. In WebService, if I want to return values from a single table I know what to do :
public DataTable GetUserDetails(string userName)
{
....
return userDetailsTable;
}
But I don't know what to do if I want to return values from different tables (a more complex data). Should I use
List<DataTable> or something else? If I use
List<DataTable> , how should I handle it in Android side? Thanks.
|
|
|
|
|
Returning things like DataTable is generally a bad idea, especially if your client needs to be lean and use minimal data resources. When you return a DataTable you get a lot of stuff returned, when you are normally just interested in the data.
What people normally do is define a class object that represents the bits of data you want to return. So if you want to return a Customer table you'll create a Customer class with properties like ID, FirstName, Surname etc, then in your web method you create a List<customer> and for each row of your datatable you'll create a Custom object, populate the properties from the fields, add it to the List<customer> and then return the List. This will greatly reduce the amount of data sent to your app, and your app now just sees a simply collection with just the data it needs.
|
|
|
|
|
Thank you very much for your reply. Can you tell me how I should make Android could handle List< Customer >? A sample code would be great. Moreover is it a good idea to send List< Customer > and List< Order > at the same time?
Thanks a lot.
|
|
|
|
|
No idea TBH, this is a c# forum, I don't know anything about Android apps. Although you are return a List, .net will convert that to json so your Android app should see something like
[{ID:1, FirstName: "John", LastName: "Doe"}, {ID=2, FirstName: "Dave", LastName: "Smith"}]
whatever framework Android has for calling web services will know how to parse that.
|
|
|
|
|
How to store the result into a byte[] with this declaration:
private static T Get<T>(string resource, out string jsonResponse) where T : class
Thanks
|
|
|
|
|