|
I think this would be better in the ASP.NET forum.
Veni, vidi, abiit domum
|
|
|
|
|
script manager only can place on one page, since all the pages i attach with master page, so it will occur error, how should i should the problem that one of the page required script manager?
|
|
|
|
|
Did you read my previous message?
Veni, vidi, abiit domum
|
|
|
|
|
inside my database have binary data. what is this problem mean
Exception Details: System.IndexOutOfRangeException: ProductImage
Source Error:
Line 70: byte[] bytes = (byte[])sqlDataReader1["ProductImage"];
SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn1.Open();
String sqlTitle1 = "SELECT * FROM ProductImage WHERE ProductID =@ID";
SqlCommand comm1 = new SqlCommand(sqlTitle1, conn1);
comm1.Parameters.AddWithValue("@ID", Id);
SqlDataReader sqlDataReader1 = comm1.ExecuteReader();
while (sqlDataReader1.Read())
{
byte[] bytes = (byte[])sqlDataReader1["ProductImage"];
string Imageitem = Convert.ToBase64String(bytes, 0, bytes.Length);
Image1.ImageUrl = "data:image/png;base64," + Imageitem;
//Image1.Visible = true;
}
conn1.Close();
my product image table
ProductID datatype nvarchar(50) primarykey
ProductColorType nvarchar(50) primarykey
ProductImg varbinary(MAX)
thx for helping 
|
|
|
|
|
byte[] bytes = (byte[])sqlDataReader1["ProductImage"];
ProductImg varbinary(MAX)
Do you see a mismatch between these two names?
Veni, vidi, abiit domum
|
|
|
|
|
haha thx ^^ i copy from old project 
|
|
|
|
|
Always a good idea to try a bit of diagnosis before posting here.
Veni, vidi, abiit domum
|
|
|
|
|
|
I'm trying to find the way how to execute a string contain c# code.
Example
string st = "if (textBox1.Text == "Jon" && chkText.Checked)
MessageBox.Show("Yes!");
else
MessageBox.Show(textBox1.Text);";
I want to execute st then i want to see the result in a message box.
Please kindly help me. Thank in advance!
|
|
|
|
|
http://support.microsoft.com/kb/304655[^]
I'd recommend against putting the MessageBox and references in your textbox there; a simple check whether the text passed as an argument would suffice. The advantage being that there's no reference from the compiled code to your UI.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
thanks but i get error.
Can u give me a small example!
|
|
|
|
|
jojoba2011 wrote: thanks but i get error. Can u give me a small example! If you'd get an error, it'd be more helpfull to solve that, than blindly trying examples.
I'm guessing that it's due to the fact that you only have the body of a method in there; just like in Visual Studio, the code needs to be located in a class. Try the example below in a console-application.
using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Microsoft.CSharp;
class Program
{
static void Main(string[] args)
{
string sources = @"
using System;
public static class ExampleClass
{
public static void ExampleMethod()
{
Console.WriteLine(""Hello World!"");
}
}";
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
string Output = "Out.dll";
CompilerParameters parameters = new CompilerParameters()
{
GenerateExecutable = false,
OutputAssembly = Output
};
CompilerResults results = codeProvider.CompileAssemblyFromSource(
parameters, sources);
if (results.Errors.Count > 0)
{
foreach (CompilerError CompErr in results.Errors)
{
Console.WriteLine(
"Line number " + CompErr.Line +
", Error Number: " + CompErr.ErrorNumber +
", '" + CompErr.ErrorText + ";");
}
}
else
{
Assembly myAssembly = Assembly.Load(File.ReadAllBytes("Out.dll"));
Type myType = myAssembly.GetType("ExampleClass");
MethodInfo mi = myType.GetMethod("ExampleMethod");
mi.Invoke(null, null);
}
Console.WriteLine("Hit any user to continue");
Console.ReadKey();
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
vote => up.
That's a very useful, and complete, example, thanks !
"What Turing gave us for the first time (and without Turing you just couldn't do any of this) is he gave us a way of thinking about and taking seriously and thinking in a disciplined way about phenomena that have, as I like to say, trillions of moving parts.
Until the late 20th century, nobody knew how to take seriously a machine with a trillion moving parts. It's just mind-boggling." Daniel C. Dennett
|
|
|
|
|
thanks in advanced!
My question is this :
Is it possible to excute code without creating any class ....?
string sources = @"
using System;
public static class ExampleClass
{
public static void ExampleMethod()
{
Console.WriteLine(""Hello World!"");
}
}";
and one more :
How to use the textBox1.Text and other controls values?
|
|
|
|
|
jojoba2011 wrote: Is it possible to excute code without creating any class ....? No. Then again, it wouldn't be much work to wrap it automatically in a class; it's just text after all. Also keep in mind that this class will not be "unloaded".
jojoba2011 wrote: How to use the textBox1.Text and other controls values? You see that using? The code one compiles needs to have a reference to your project. That means including a "using" directive in the source code, as well as adding a reference[^] to the compilerparameters.
You could save a lot of pain by rewriting that part of the code to use variables/parameters, and not directly the UI-elements of your project.
--edit;
Alternatively, if you'd install Mono, there'd be the Eval[^] method.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
modified 16-Nov-13 16:18pm.
|
|
|
|
|
When I'm debugging, I do the following
string st = something
if (textBox1.Text == "Jon" && chkText.Checked)
MessageBox.Show(st + " (if)");
else
MessageBox.Show(st + " (else)");"
|
|
|
|
|
|
i got the solution :
http://stackoverflow.com/questions/14485226/convert-string-to-executable-c-sharp-code-in-code-behind
Solved !
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
private System.Windows.Forms.TextBox txtf;
private System.Windows.Forms.TextBox txts;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txt;
//public Form1()
//{
// InitializeComponent();
//}
public Form1()
{
this.txtf = new System.Windows.Forms.TextBox();
this.txts = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.txt = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// txtf
//
this.txtf.Location = new System.Drawing.Point(81, 125);
this.txtf.Name = "txtf";
this.txtf.Size = new System.Drawing.Size(100, 20);
this.txtf.TabIndex = 0;
//
// txts
//
this.txts.Location = new System.Drawing.Point(81, 161);
this.txts.Name = "txts";
this.txts.Size = new System.Drawing.Size(100, 20);
this.txts.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(81, 196);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txt
//
this.txt.Location = new System.Drawing.Point(12, 12);
this.txt.Multiline = true;
this.txt.Name = "txt";
this.txt.Size = new System.Drawing.Size(260, 107);
this.txt.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.button1);
this.Controls.Add(this.txts);
this.Controls.Add(this.txt);
this.Controls.Add(this.txtf);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private static string CreateExecuteMethodTemplate(string content)
{
var builder = new StringBuilder();
builder.Append("using System;");
builder.Append("\r\nnamespace Lab");
builder.Append("\r\n{");
builder.Append("\r\npublic sealed class Cal");
builder.Append("\r\n{");
builder.Append("\r\npublic static object Execute()");
builder.Append("\r\n{");
//builder.AppendFormat("\r\nreturn {0};", content);
builder.AppendFormat("\r\n {0} ", content);
builder.Append("\r\n}");
builder.Append("\r\n}");
builder.Append("\r\n}");
return builder.ToString();
}
private static object Execute(string content)
{
var codeProvider = new CSharpCodeProvider();
var compilerParameters = new CompilerParameters
{
GenerateExecutable = false,
GenerateInMemory = true
};
compilerParameters.ReferencedAssemblies.Add("system.dll");
string sourceCode = CreateExecuteMethodTemplate(content);
CompilerResults compilerResults = codeProvider.CompileAssemblyFromSource(compilerParameters, sourceCode);
Assembly assembly = compilerResults.CompiledAssembly;
Type type = assembly.GetType("Lab.Cal");
MethodInfo methodInfo = type.GetMethod("Execute");
return methodInfo.Invoke(null, null);
}
private void button1_Click(object sender, EventArgs e)
{
string Matn = txt.Text;
Matn = Matn.Replace(txtf.Name, txtf.Text);
Matn = Matn.Replace(txts.Name, txts.Text);
var result = new object();
result = Execute(Matn);
MessageBox.Show(result.ToString());
//result =Execute("DateTime.Now");
//result = Execute("if(\"ali\"==\"ali\")return \"true\"; else return \"false\";");
}
}
}
|
|
|
|
|
I've been trying to run a simple block of code from C sharp in a powershell run space.
I went to run that command in the powershell example project on my workstation and it did not work, but that demo application will run on the server that has scom installed.
Is there a management pack (like with Exchange) that I need to install on my workstation to get access to the dlls and commands that I have through powershell when on the server locally. Any ideas?
Import-Module –Name OperationsManager
New-SCOMManagementGroupConnection -ComputerName "serverName"
get-scomgroup
foreach ($group in get-scomgroup)
{
Write-Host $group
}
How to run PowerShell scripts from C#[^]
|
|
|
|
|
Explained here[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you Eddy.
I also had a hard time getting a PS namespace going inside of c sharp, but was able to get that going late last night locally and then modified it to work remotely. I will post those functions for reference here when I get back to work on Monday and compare what I'm doing to powershell girls code.
|
|
|
|
|
I am looking for more information on how to prevent thread starvation/blocking/racing in an application or service that could possibly running up to 200 threads simultaneously across multiple processors/cores.
Most of the examples I have found online show how to coordinate between 3 or 4 threads max and I am planning a app that will have hundreds.
I've made applications that have run up to 30 threads but when going way beyond that I am worried about some threads not getting any CPU time not to mention synchronization.
Where can I find some really good articles and blogs?
What are the best books on the subject?
There are a lot of books and articles on the subject, I am looking for the most informative and instructional but not presented in an engineering language above my understanding.
I originally posted this on the Q and A forum and it was suggested that I also imply about it on the C# forum.
All suggestions are appreciated.
|
|
|
|
|
I suppose I have to be the typical "that" guy but...
Why do you suppose you need 200 threads? You do realize that dividing work, once you reach the number of cores you may be degrading performance instead of improving it? More threads does not mean more throughput, I suppose I don't know what you are really trying to do, but maybe a good design review is needed before starting down a rather disappointing path...
|
|
|
|
|
I am working on a modular processing model and I was thinking scalability. My current model would be for 20-40 threads. However, if the job became very large scale like processing millions of records every hour, how could I expand the scale while still giving each thread its own slice of CPU time and not having any threads get starved out.
|
|
|
|
|
Without knowing more about your problem space:
I'd suggest building a queue (or queues) of the different types of processing (items in the queue are the data for a given processing type) and having threads that loop around: remove item from the queue and process it. As long as there is something in the queue, the threads will do work. When there's nothing there, there's no work to do.
Determine the number of threads (by experimentation(?) on your hardware) that gives near-optimal performance.
It's possible that if things are IO bound or processed off-the-box (e.g., SQL server) the best number of threads will be more or less than the number of cores.
(Or have the application try to self-tune?)
|
|
|
|