|
Perhaps a better explaination of using "Interface"?
|
|
|
|
|
Blubbo wrote: Perhaps a better explaination of using "Interface"?
???
It's time for a new signature.
|
|
|
|
|
Blubbo wrote: I've got 2 devices but only got 1 (crashes when doing the 2nd devices in SeekHidDevices method during ReadPort calling.
I don't understand this bit at all...
But - how can you have created a reference to project a in project b as well as a reference to project b in project a? That's circular and shouldn't allow you to add the reference in the first place (in VS it gives you an error when you try to add the reference)
What you need to do is have project C which contains 'utility' functions - A and B both reference C - C can contain utility methods, classes, anything that needs to be more generally accessed.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Okay. I get the a bit of the idea what you're saying. Any example on this?
|
|
|
|
|
Hi,
I have a problem when i try to use stored procedure in C#.net. Well when i run the stored procedure in sql server , it works fine and when the same query if i run in C#.net without using stored procedure, it works fine too. But when i try to use stored procedure in c#.net, it gave errors. The error is like this:
System.Data.SqlClient.SqlException: The EXECUTE permission was denied on the object 'SelectItem', database 'Student', schema 'dbo'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at Default_View.DisplayItem() in C:\Documents and Settings\smanandhar\My Documents\Visual Studio 2008\Projects\StudentPortlet\Default_View.ascx.cs:line 285
the stored procedure is :
ALTER PROCEDURE [dbo].[SelectItem]
@UserID nvarchar (50)
AS
BEGIN TRANSACTION
select i.Item,i.ItemDescription,i.Category,i.Amount,i.SubmissionDate,i.ProposalID from ProposalItem i,Proposal j where
i.ProposalID = j.ID
and
j.UserID = @UserID
COMMIT TRANSACTION
and the code in C# is:
try
{
SqlConnection cnx = new SqlConnection(StudentPortlet.strCnx);
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand("SelectItem", cnx);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@UserID", SqlDbType.NVarChar).Value = "Unknown";
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataSet dtt = new DataSet("student senate budget testing");
adap.Fill(dtt);
System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid();
grid.HeaderStyle.Font.Bold = true;
grid.DataSource = dtt;
grid.DataBind();
dgDisplayItem.DataSource = dtt;
dgDisplayItem.DataBind();
}
catch (Exception ex)
{
string s = ex.ToString();
}
sm
|
|
|
|
|
The problem is right in what you posted " The EXECUTE permission was denied on the object 'SelectItem', database 'Student', schema 'dbo'". What user is your site running as? And what does your connection string look like?
|
|
|
|
|
I defined the connection string in a class and the connection string looks like
public static string strCnx = "server=D324KJ43H2;uid=user;pwd=northpoint;database=Student"
I am login as administrator..
suchita
|
|
|
|
|
Use the following query to give execute permission to the procedure
GRANT EXECUTE TO SelectItem
Gg
http://ggaben-developer.blogspot.com/
|
|
|
|
|
hi
can any one suggest me quickest(optimized) way to call an stored procedure from my c# code for every row of data table (rows can be for example 20000)? what is "optimized" ?
|
|
|
|
|
SqlCommand command = new SqlCommand();
command.Connection = ...
command.CommandText = "sp_name";
command.Paramaters.Add("@paramName, System.Data.SqlTypes.SqlDecimal).Value = 0m; //use correct type param
using(SqlDataReader reader = command.ExecuteReader()){
while(reader.Read()){
//The reader contains the columns of each record
}
}//end using
|
|
|
|
|
Hello,
is there any possible and simple way to convert a Dictionary to a JSON-String an of course to convert it in the other direction (JSON-String to Dictionary)?
I've searched a lot, but i havent't found a simple solution.
Thank you
|
|
|
|
|
You can use Json.NET[^] for the same.
However, I have found one class which converts Dictionary to String that might help you.
class ConvertDictionary
{
Dictionary<string, int> _dictionary = new Dictionary<string, int>()
{
{"salmon", 5},
{"tuna", 6},
{"clam", 2},
{"asparagus", 3}
};
public ConvertDictionary()
{
string s = GetLine(_dictionary);
File.WriteAllText("dict.txt", s);
Dictionary<string, int> d = GetDict("dict.txt");
}
string GetLine(Dictionary<string, int> d)
{
StringBuilder builder = new StringBuilder();
foreach (KeyValuePair<string, int> pair in d)
{
builder.Append(pair.Key).Append(":").Append(pair.Value).Append(',');
}
string result = builder.ToString();
result = result.TrimEnd(',');
return result;
}
Dictionary<string, int> GetDict(string f)
{
Dictionary<string, int> d = new Dictionary<string, int>();
string s = File.ReadAllText(f);
string[] tokens = s.Split(new char[] { ':', ',' },
StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < tokens.Length; i += 2)
{
string name = tokens[i];
string freq = tokens[i + 1];
int count = int.Parse(freq);
if (d.ContainsKey(name))
{
d[name] += count;
}
else
{
d.Add(name, count);
}
}
return d;
}
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi,
I've a listbox having few items. I'm trying to move up a selected item in listbox, using Up button. below is the code in btnUp_Click event. Its working fine. Sometimes, its not working.. In debug mode, its executing all the statements. Please let me where it went wrong.. Thanks in advance.
if (lbAllFields.SelectedIndex > 0)
{
int ndx = lbAllFields.SelectedIndex;
string item = (string)lbAllFields.SelectedItem;
lbAllFields.Items.RemoveAt(ndx);
lbAllFields.Items.Insert(ndx - 1, item);
lbAllFields.SelectedIndex = ndx - 1;
}
|
|
|
|
|
Find following code for the same.
if(ListBox1.SelectedIndex!=0)
{
int i = ListBox1.SelectedIndex;
string s = ListBox1.Items[i].Text;
string s1 = ListBox1.Items[i - 1].Text;
ListBox1.Items[i-1].Text = s;
ListBox1.Items[i].Text = s1;
}
if(ListBox1.SelectedIndex!=ListBox1.Items.Count)
{
int i = ListBox1.SelectedIndex;
string s = ListBox1.Items[i].Text;
string s1 = ListBox1.Items[i + 1].Text;
ListBox1.Items[i+1].Text = s;
ListBox1.Items[i].Text = s1;
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Thanks alot.. its working
|
|
|
|
|
I assume that reflection is what I'd need for this but I can't seem to find the necessary information and thought I'd turn to CP.
Let's say I have a class with a few different member variables:
public class myClass
{
public int myInt;
public string myString;
public byte myByte;
}
Now I'd like to access one of the member variables in an instance of the class, based on a string variable available at run time. The following piece of code would do the job but, as you can imagine it would become very unwieldy if the class had a lot of member variables and I'd like to have it more generic anyway.
myClass myInstance = new myClass();
string whichMember;
string myValue;
.
.
.
switch (whichMember)
{
case "myInt": myValue = myInstance.myInt.ToString(); break;
case "myString": myValue = myInstance.myString; break;
case "myByte": myValue = myInstance.myByte.ToString(); break;
}
|
|
|
|
|
myInstance.GetType().GetProperty(whichMember)
and you can use GetValue for getting the value from this returned object.
|
|
|
|
|
Great stuff! Thanks. It works like a charm, although I had to use GetField as opposed to GetProperty.
|
|
|
|
|
Yes, Reflection. But because Reflection tends to be slow, if you do it a lot I recommend caching the MethodInfos in a dictionary or other collection: Dictionary<Type,Dictionary<string,MethodInfo>> then access them from there.
I seem to recall a similar question coming up in the last six months or so.
Edit: Well, it's not really on topic, but it may be interesting anyway
http://www.codeproject.com/Messages/3421980/Re-Calling-MethodBases-Invoke-on-a-constructor-ref.aspx[^]
modified on Thursday, July 15, 2010 9:42 AM
|
|
|
|
|
Thanks. Using a collection to cache the MethodInfos is probably not necessary for my application but it's a good idea that I will flag for future use.
|
|
|
|
|
I have a project in c# Windows Form
My program is working on the internet
and on my computer program working without problem.
but when user try to program they are getting proxy error.
Because my proxy and user proxy differnt.
and What should I do?
and I'm sorry. My English not good.
|
|
|
|
|
Add the following entry in the application config file:
<configuration>
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
</configuration>
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I have a start up form call MainForm called as follows...
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
On MainForm I have a MenuStrip with MenuItems and ToolStripMenuItems.
Some of these ToolStripMenuItems have a property of CheckOnClick set to True.
From MainForm I open another form called f1 based on HormoneTypeForm, as an MDI child...
private void hormoneTypeToolStripMenuItem_Click(object sender, EventArgs e)
{
HormoneTypeForm f1 = new HormoneTypeForm();
f1.MdiParent = this;
hormoneTypeToolStripMenuItem.Enabled = false;
f1.Show();
}
My question is -
From form f1 how do I get ( or set ) the Checked value of some
of the ToolStripMenuItems on the MainForm menu?
What I want to do in form f1 is take actions conditional on the Checked value of some ToolStripMenuItems on the main form MainForm (MdiParent).
I cannot find anyway to reference the MainForm ToolStripMenuItems properties from form f1.
I'm sure it simple but.....?
Thanks for any help.
modified on Saturday, July 31, 2010 4:51 AM
|
|
|
|
|
You can made one function on mainform which will return the value of
ToolStripMenuItem. And before showing the form f1 assign the value of it to some
variable to f1 as follows.
f1.Somevariable=this.Returnvalueoftoolstripmenuitem();
f1.Show();
That's it.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Thanks, the problem with that ( I think ) is that the value of the ToolStripMenuItem could be changed subsequently by another open MdiChild form.
One way that I can get half of what I need is to have a public static variable in a static class ( say my starting code ) which I can access from all of my forms. I can then set the value of this to the value of the ToolStripMenuItem.Checked property in the CheckedChanged event handler for the ToolStripMenuItem.
I can then check ToolStripMenuItem.Checked for a certain condition from any child form.
But.... how can I Set the ToolStripMenuItem.Checked property in code?
It may help if I give a better example of what I want to do.
In MainForm ( the MdiParent form ) I have a confirmDeletesToolStripMenuItem with CheckOnClick set to True.
In any child form, during the delete process, if MainForm confirmDeletesToolStripMenuItem.Checked == True; then they will get a Confirm Deletes Message Box or not if False.
In the Confirm Deletes Message Box I will also have a CheckBox option "Do not show again for this session" that if checked will Set the MainForm confirmDeletesToolStripMenuItem.Checked = False; .
I guess I can also use Application Settings and set this type of thing in an Options form rather than on a Checked ToolStripMenuItem, however I'm sure there will be other reasons Get/Set the value of the Parent form from Child?
|
|
|
|
|