|
Wish I could claim the credit - if that article by loneferret helped you then be sure to give it an up-vote
|
|
|
|
|
|
I am updating my all in one IServiceProvider IoC container.
Previously I was only accessing public type, public constructors, public properties.
Now I am also checking private stuff.
Now when I run my console app.
Assembly a;
a.DefinedTypes
Work fine and I can enumerate them and instantiate them. Whether or not they are private type.
But I suspect there are circumstance where this utility class won't be working.. In fact my .NET security is... tenuous... but you could reduce the right of a piece of code...
How to check whether or not I can do those private reflective operation or not?!
When Can't I do them?
|
|
|
|
|
Im very new to C# and am trying to use conversion tools to change some VB over. Im not quite sure how to remedy this error, so any help I can get is greatly appreciated!
This is the error Im receiving:
"CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.LinkButton'. An explicit conversion exists (are you missing a cast?)"
for Line 93
myDeleteButton = myTableCell.Controls[0];
Here is the full C# code:
public void Page_Load(object Source, EventArgs E)
{
if (!Page.IsPostBack)
{
BindData();
}
}
public void BindData()
{
DataSet myDataSet = new DataSet();
SqlDataAdapter mySqlDataAdapter = default(SqlDataAdapter);
mySqlDataAdapter = new SqlDataAdapter("SELECT * FROM glmaster", "REMOVED;");
mySqlDataAdapter.Fill(myDataSet, "glmaster");
glmasterInfo.DataSource = myDataSet.Tables["glmaster"];
glmasterInfo.DataBind();
}
public void DataGrid_Delete(object Source, DataGridCommandEventArgs E)
{
SqlConnection myConnection = default(SqlConnection);
SqlCommand myCommand = default(SqlCommand);
string strDeleteStmt = "";
decimal balance_test = new decimal();
string Balance_output = "";
balance_test = System.Convert.ToDecimal(Convert.ToDecimal(E.Item.Cells[6].Text));
if (balance_test == 0.0M)
{
outError.InnerHtml = "";
strDeleteStmt = "DELETE FROM glmaster " +
" WHERE major = " + E.Item.Cells[1].Text +
" AND minor = " + E.Item.Cells[2].Text +
" AND sub1 = " + E.Item.Cells[3].Text +
" AND sub2 = " + E.Item.Cells[4].Text;
try
{
myConnection = new SqlConnection(
"REMOVED;");
myCommand = new SqlCommand(strDeleteStmt, myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
glmasterInfo.EditItemIndex = -1;
BindData();
}
catch (Exception exc)
{
outError.InnerHtml = "* Error while deleting data.<br />"
+ exc.Message + "<br />" + exc.Source;
}
finally
{
myConnection.Close();
}
}
else
{
Balance_output = balance_test.ToString("C");
string Error_String = "";
Error_String = "<center>You Can\'t Delete This Account<br>";
Error_String = Error_String + "Balance is NOT zero.<br>";
Error_String = Error_String + "The Account Balance is " + Balance_output;
Error_String = Error_String + " for ";
Error_String = Error_String + E.Item.Cells[1].Text + "-";
Error_String = Error_String + E.Item.Cells[2].Text + "-";
Error_String = Error_String + E.Item.Cells[3].Text + "-";
Error_String = Error_String + E.Item.Cells[4].Text + "</center>";
outError.InnerHtml = Error_String;
}
}
public void DataGrid_ItemCreated(object Sender, DataGridItemEventArgs e)
{
if (((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) || (e.Item.ItemType == ListItemType.EditItem))
{
TableCell myTableCell = default(TableCell);
myTableCell = e.Item.Cells[0];
LinkButton myDeleteButton = default(LinkButton);
myDeleteButton = myTableCell.Controls[0];
myDeleteButton.Attributes.Add("onclick", "javascript: return confirm(\'Are you Sure you want to delete this account?\');");
}
}
modified 19-Apr-16 11:29am.
|
|
|
|
|
It would really help us to help you if you actually indicated (with a comment) where the error occurs.
|
|
|
|
|
sorry about that. Line 93
myDeleteButton = myTableCell.Controls[0];
|
|
|
|
|
Please edit your original question and add the information there, so anyone else reading the question can see the details.
|
|
|
|
|
|
Your first suggestion worked perfectly! Thanks so much for your help
|
|
|
|
|
|
Ill be sure to work on it. Thanks
|
|
|
|
|
I have created a windows File watcher Service which works fine on Development PC but when i am trying to install and start in other PC , it throws an error
Windows could not start the {name of service} service on Local Computer. Error 1067: The process terminated unexpectedly.
Please help
|
|
|
|
|
Means there has been an exception that you did not handle, or that there was no work. Does the folder that you are watching exist? Does the service (that runs under different credentials than the user) have the correct rights to access that directory?
Open the services, locate yours, right-click and change the user under which it runs to your account.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am new to UWP, so please forgive me!
I have been trying to implement a TCP Server \ Client, as outlined in the Microsoft example:
[^]
If I try this out on my local machine, it works fine (app generates server & client). If I then try on my remote machine (Minnowboard Turbot), I dont get a connection, or receive any data.
I have also tried (from both Local & Remote machine) connecting to a TCP Server program that I already have written. Whilst I get a connection to the server, I dont receive any data from the server (which is sending data every second).
Does anyone know what mistake I am making?
Thanks for any advice
Mike
|
|
|
|
|
Such problems are usually sourced by firewalls filtering out the data packets.
You must configure the local Windows firewall for the system running the server process to accept incoming packets on the listening port.
If the systems are not in the same subnet (local network), it may be also necessary to allow the same packets on the firewall of the server side (e.g. a router).
|
|
|
|
|
Hi Jochen, thanks for your help!
I have had a little more success. In the project capabilities, I just had Private Networks (Client & Server) ticked. I have now ticked Internet (Client & Server), and my test project is now able to send & receive data on both the local & remote machine (to itself (ie app is client & server)). If I create 2 projects - one server, one client and run one on the Local & one on the Remote, it can now connect, Send & Receive in either direction.
If I then try to connect my Client to my Original Server (written Visual studio C# 2010), I can connect from my Client and send data (from Client to Server). I DO NOT however receive any data from my Server to my client. This is the same for either the Local or Remote machines.
I have just fired up Wireshark, and this does see the Server Sent client.
My Client Code is this:
private async void CreateClient()
{
try
{
socket = new Windows.Networking.Sockets.StreamSocket();
Windows.Networking.HostName serverHost = new Windows.Networking.HostName("192.168.1.19");
string serverPort = "7001";
await socket.ConnectAsync(serverHost, serverPort);
Stream streamIn = socket.InputStream.AsStreamForRead();
streamIn.Flush();
StreamReader reader = new StreamReader(streamIn);
while (true)
{
string response = await reader.ReadLineAsync();
}
}
catch (Exception e)
{
}
}
Has anyone any suggestions?
Thanks
Mike
|
|
|
|
|
This is difficult to answer with the available information.
You did not show the code that is sending to the server.
So I can just guess that you are doing that before creating the input stream and the reader. Then the data from the server may have been received already and are discarded by calling Flush() .
I can only suggest to try it this way:
Stream streamIn = socket.InputStream.AsStreamForRead();
StreamReader reader = new StreamReader(streamIn);
while (true)
{
string response = await reader.ReadLineAsync();
}
If this does not help you should debug the client code.
|
|
|
|
|
Ah, I have got it working!
What I have done is added a '\r' (or '\n') to the end of the string of data being sent from my Server program (written in VS2010 C#). The data is now seen by the Client when the app is run on BOTH the Local & Remote Machine.
I dont need to '\r' character when sending FROM Client TO Server for the server to see the data.
Don't know why my program worked with VS2010 (client & server), but now has to be modded, to work with VS2015 Client. Guess as it now works, I am not too bothered!
Thanks for your time & help!
Mike
|
|
|
|
|
Fine to know that you have finally solved the problem.
The reason is quite simple:
You are using ReadLineAsync which reads line by line (until a new line character is received). So you won't get anything if there is no new line character. Your server code uses probably a different (not text / line oriented) method.
|
|
|
|
|
Hi,
I am looking for code sample in C# which I can use to login to a website programmatically.
I want to provide Username and Password through the code and it should go to the next page after Logging in.
Regards,
mba
|
|
|
|
|
|
|
In my application, I have to change the system date/time over and over to debug and test and use it.
The problem is, if I forget to change it back and edit a file "in the past", Visual studio doesnt know to recompile that file when I press F5.
Is there any to disable this behavior?
|
|
|
|
|
No, there is not way to turn it off.
This is the expected behavior because VS will try to save time by only compiling the files that have been updated since the last compile.
The solution is rather simple. Instead of hitting Build (F5 (start debugging) or F6 (build)), hit Build menu -> Rebuild Solution or Rebuild project and it'll rebuild the entire solution or project, including all dependencies.
|
|
|
|
|