Hi All,
I have a barcode scanner(Symbol) but i dont know how to read information from it to my application (in C#). Can anyone help me in this problem with sample code?
Geetha.
I'm reading data from a serial port, but the DataReceived event of SerialPort is handled on it's own thread. I want to handle this on the main thread, but simply declaring an event and raising it still results in it being processed on the SerialPort thread. I'm assuming I need to declare a delegate I can call, but I don't see how that would work.
For example, I want to call Sub HandleDataReceived() on the main thread from the DataReceived thread, having HandleDataReceived() run on the main thread. How would I do this?
Hi,
if I put a custom class in session, then in an action method I get an instance of that class from session, and populate some fields, I noticed that when a different controller gets that class from session, those fields are populated. Even though after the first call didn't save the updated class back in session.
is this typical behavior for session objects?
I thought I had to use keyword 'static' on the class in session for this to happen
thanks
I have a C# function that does some processing and needs to return figures about what it has processed, success, failure, etc.
Can anyone tell me if there are any standard framework classes that will handle this (for example, number of records processed, number successful, failed, etc) ?
Alternatively, can anyone say how they usually handle this? Is the best way to create a class, or to use out parameters?
How to set up auto mapping to map System.Collections.Generics.ISet<T> correctly?
I tried implementing IHasManyConvention, but in intellisense it seems that IOneToManyCollectionInstance does not have anything for that(?)
I have written a simple delete query
delete from mails
While I execute I get no problem and the query runs fine, but when I publish the website I get an error stating:
"Could not delete from specified
tables"
What might be the problem?
I am getting this error when placed in IIS but when i run it in local drive through visual studio i am not getting this error...please help
[MetadataType(typeof(Deal_Validation))]
public partial class Deal
{
}
public class Deal_Validation
{
[Required]
public string Title { get; set; }
public double? EstValue { set; get; }
}
How to validate EstValue (check if it is of type double?)
Thanks
Hi all,
I've got a conditional compilation symbol I'm using called "RELEASE", that I indicated in my project's properties in Visual Studio. I want some particular CSS to be applied to elements when the RELEASE symbol is defined, and I was trying to do that from the view, but it doesn't seem to be working.
My view code looks like this (shortened a bit for demo purposes):
<% #if (RELEASE) %>
<div class="releaseBanner">Banner text here</div>
<% #else %>
<div class="debugBanner">Banner text here</div>
<% #endif %>
With this code, and with the RELEASE symbol set, the 'else' code is running and I'm getting a div with the debugBanner class. So it doesn't seem to think that RELEASE is defined. It's worth noting that my actual C# code in .cs files is recognizing RELEASE and runs the correct code. It's only the view that is giving me the problem.
Does anyone have any insight into this? Any help would be appreciated. Thanks.
Is is possible to have a partial view inherit more than one model? I have three models (Contacts, Clients, Vendors) that all have address information (Address). In the interest of being DRY I pulled the address info into it's own model, Addresses. I created a partial create / update view of addresses and what to render this in other other three model's create / update views.
I've seen developers use two approaches when they are done with a session object.
1) Session.Remove(key)
2) Session(key) = nothing
What is the better approach of the two above? Does Session.Remove dispose the object stored automatically?
Does the second approach depend on the garbage collector to actually free up the memory?
Thanks.
I have a very big table with a lot of rows, every row has stats for every user for certain days. And obviously I don't have any stats for future. So to update the stats I use
UPDATE Stats SET Visits=@val WHERE ... a lot of conditions ... AND Date=@Today
But what if the row doesn't exist? I'd have to use
INSERT INTO Stats (...) VALUES (Visits=@val, ..., Date=@Today)
How can I check if the row exists or not? Is there any way different from doing the COUNT(*)?
If I fill the table with empty cells, it'd take hundreds of thousands of rows taking megabytes and storing no data.
Hi guys, i have a problem with cross-domain cookies. I read a lot of documentation about sharing cookies between subdomains. The main idea of all articles is set Domain property to something like ".mydomain.com". I've created two domains on local IIS server - test1.local.boo and test2.local.boo. They works great and visible with browser. I have the following code:
Site test1 - Writes cookie:
HttpCookie myCookie = new HttpCookie("TestCookie");
myCookie.Domain = ".local.boo";
myCookie["msg"] = "Welcome from Cookie";
Response.Cookies.Add(myCookie);
Site test2 - Reads cookie:
HttpCookie cookie = Request.Cookies["TestCookie"];
if (cookie != null)
{
Response.Write(cookie["msg"]);
}
else
{
Response.Write("FAILED");
}
This code always shows FAILED message. So it means that second site can't read cookie from the same subdomain. Where is my mistake??
SPL and PHP allows you to create objects on the fly from classes, that fulfill certain conditions, such as implementing certain interfaces and stuff like that.
However, I would like to do something similar in c# and automatically create objects from all classes in a namespace and invoke a particular method from those classes that implement a certain interface.
My experience developing desktop apps is very limited. I am not quite sure if I should use delegates to archive this or if reflection is really the way to go.
Assume I have method
void SomeMethod(Action callback)
This method does some work in background thread and then invokes callback. The question is - how to block current thread until callback is called ?
There is an example
bool finished = false;
SomeMethod(delegate{
finished = true;
});
while(!finished)
Thread.Sleep();
But I'm sure there should be better way
I am packing bytes into a struct, and some of them correspond to a Unicode string. The following works fine for an ASCII string:
[StructLayout(LayoutKind.Sequential)]
private struct PacketBytes
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string MyString;
}
I assumed that I could do
[StructLayout(LayoutKind.Sequential)]
private struct PacketBytes
{
[MarshalAs(UnmanagedType.LPWStr, SizeConst = 32)]
public string MyString;
}
to make it Unicode, but that didn't work. (Since this field is part of a struct with other fields, which I've omitted for clarity, I can't simply change the CharSet of the containing struct.)
Any idea what I'm doing wrong?
I need help. I'm having problem in my program. This is my code on my Business logic layer.
Function Load_ItemDetails(ByVal ItemID As String) As Items
Dim objItemEnt As New tblitem
Dim objitem As New Items
Try
Using da = New DataAccess
objItemEnt = da.Load_ItemDetails(ItemID)
With objitem
.ItemCode = objItemEnt.ItemCode
.ItemName = objItemEnt.ItemName
.Description = objItemEnt.Description
.NameofType = objItemEnt.NameofType
.TypeofPricing = objItemEnt.TypeofPricing
.OnStock = objItemEnt.OnStock
.ItemPrice = objItemEnt.ItemPrice
.DateModified = objItemEnt.DateModified
End With
Return objitem
End Using
Catch ex As Exception
Throw
End Try
End Function
This code is for my data access layer.
Public Function Load_ItemDetails(ByVal ItemCode As String)
Dim objitem As New tblitem
Try
Using entItem = New DAL.systemdbEntities1
Dim qryUsers = From p In entItem.tblitems
Where p.ItemCode = ItemCode
Select p
Dim luser As List(Of tblitem) = qryUsers.ToList
If luser.Count > 0 Then
Return luser.First
Else
Return objitem
End If
End Using
Catch ex As Exception
Throw
End Try
End Function`
For my Presentation layer:
Private Sub Load_Item_Detail(ByVal ItemCode As String)
objItem = New Items
Using objLogic = New LogicalLayer
objItem = objLogic.Load_ItemDetails(ItemCode)
With objItem
Me.ItemCodetxt.Text = .ItemCode
Me.ItemNametxt.Text = .ItemName
Me.ItemDesctxt.Text = .Description
Me.ItemTypetxt.Text = .NameofType
Me.ItemPricetxt.Text = .TypeofPricing
Me.ItemOnstocktxt.Text = CStr(.OnStock)
Me.ItemPricetxt.Text = CStr(.ItemPrice)
Me.TextBox1.Text = CStr(.DateModified)
Me.ItemCodetxt.Tag = .ItemCode
End With
End Using
End Sub`
and after I run, I get this error Nullable object must have a value help me. I'm stuck. I don't know what to do guys. I new in n tier architecture.
I have a list box which is populated using a dictioanry. When I iterate throught the selected items using the following code, it always show only the first items as selected - even if the first item is not selected.
Have you ever encountered this scenario?
Could you please help on this?
foreach (ListItem item in lstProcessName.Items)
{
if (item.Selected == true)
{
selectedNewSales.Add(item.Text);
}
}
I need to download a LARGE file (2GB) over HTTP in a C# console app. Problem is, after about 1.2GB, the app runs out of memory.
Here's the code I'm using:
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(username, password);
byte[] fileData = request.DownloadData(baseURL + fName);
As you can see... I'm reading the file directly into memory. I'm pretty sure I could solve this if I were to read the data back from HTTP in chunks and write it to a file on disk.
Does anyone know how I could do this?
i have a validationSummary in my page. i want to call a javascript function after the validationSummary is filled. how can i achieve this?
i think i should add an attribute in the code behind, but i can't figure out what is the attribute's key.
any help?
In my aspx page I have drop down list that initialy in page load event loads up with list of values which is shown to client(drop down list "A") and in client side, depending on client selecion of another drop down list(drop down list "B") I have written a javascript to update drop down list "A" with corresponding values with Ajax behaviour(without full page postback).
But when we post page to the server, in server side page load event shows initialy sent list of values for drop down list "A" but not the values that were loaded by Ajax calls due to ViewState not being updated correctly due to Ajax call. I could fix this easily with update panel but it increased Ajax request size to 44KB which is much higher than what currently is for hand made Ajax script I have written( 0.5KB) Is there special way of fixing this rather than using update panel?
Hi
I have the following code sample, where the only difference between the 2 parts of the If statement is the less than/greater than operators.
Is there a better way to write this? Could almost do with being able to define an Operator variable.
If myVar = true Then
Do While (X < Y)
'call Method A
Loop
Else
Do While (X > Y)
'call Method A
Loop
End If
thanks
I'm trying to bring a C++ library into C#, so naturally I am trying to make a C++/CLI project.
In visual studio I created a new project (Visual C++ project, class library). I then tried to make a test class out of the pre-generated "Class1"
namespace Test {
public ref class TestIt
{
public:
void DoWork()
{
System::Console::WriteLine("sup");
}
// TODO: Add your methods for this class here.
};
}
So I compile in and go to the build folder.... hrmm no .dll wetf?? There's a .dll.intermediate.manifest file, but no .dll.
So wut I did wrong?