|
In a C# 2010 application, I am using linq to sql to connnect to a sql server 2008 database. From the linq statement listed below,
I am trying to obtain the OrgName as a string value. However I keep getting errors trying to make this occur.
string strCustnUM = CUSTOMERNUMBER;
var varOrgName = (from o in rData.Orgs
join pl in rData.Custs on o.OrgID equals pl.OrgID
where pl.orgnum == strContract
select(o.OrgName).SingleOrDefault());
string strOrgName = Convert.ToString(varOrgName);
Thus can you tell me how to change the linq statement so that I obtain the OrgName as a string value that I can use in the C# application?
|
|
|
|
|
Hmm, the structure of the query looks interesting. Try this:
var varOrgName = (from o in rData.Orgs
join pl in rData.Custs on o.OrgID equals pl.OrgID
where pl.orgnum == strContract
select o.OrgName)
.SingleOrDefault();
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt (above) is right, if that doesn't solve your problem, could you copy-paste the error you get, and tell us the data type of o.OrgName?
|
|
|
|
|
Can anyone explain me, What is EncoderValue.CompressionLZW in C#
|
|
|
|
|
It specifies that you want to save an image using LZW compression.
/ravi
|
|
|
|
|
These enumerations are specified when JPEG or TIFF encoders are being used with the Image.Save method.
This particular value specifies the LZW compression scheme. Can be passed to the TIFF encoder as a parameter that belongs to the Compression category.
|
|
|
|
|
I have a generic queue. in that queue multiple threads will enqueue and one thread will dequeue from it. Now i am using lock(object) for enqueue and dequeue oprations. But i need a lock free mechanism for this as we have a Queue.Synchronized() method for Queue. Is there any better mechanism for this, because i am dealing with millions of records.
advance Thanks for replies
|
|
|
|
|
There's no such thing as a "lock free" method of doing this.
Internally, the Synchronized collections all use some kind of locking mechanism to keep them thread-safe. I believe ConcurrentQueue uses the SpinWait class, which is a nothing more than a Thread.Yield and Sleep wrapped in a counter.
|
|
|
|
|
I am using LINQ in my project. I have tried using update query. But this is not working for me.
Please any body help me. Did I need to change any settings of my database? or for the datacontext?
My code is as follows:
here dc is the datacontext, getinteger() is an extension method, ucItem is a custom control,
Common is a class
if (clsTblAsset.AssetId == 0)
{
clsTblAsset.StockId = ucItem._Id.getInteger();
clsTblAsset.RefId = 0;
clsTblAsset.RefModule = "S";
clsTblAsset.AssetEntryDate = DateTime.Now.Date.getDateTime();
clsTblAsset.LoginId = ClsParameters.LogInId;
Common.dc.TblAssets.InsertOnSubmit(clsTblAsset);
}
Common.dc.SubmitChanges();
Can any body help me now please..
Regards,
Jineesh
|
|
|
|
|
jini4 wrote: But this is not working for me.
Sorry, my crystal ball is at the cleaners, could you - just this once - tell me what the problem is.
|
|
|
|
|
Hi J4amieC
My code is as follows:
here dc is the datacontext, getinteger() is an extension method, ucItem is a custom control,
Common is a class
if (clsTblAsset.AssetId == 0)
{
clsTblAsset.StockId = ucItem._Id.getInteger();
clsTblAsset.RefId = 0;
clsTblAsset.RefModule = "S";
clsTblAsset.AssetEntryDate = DateTime.Now.Date.getDateTime();
clsTblAsset.LoginId = ClsParameters.LogInId;
Common.dc.TblAssets.InsertOnSubmit(clsTblAsset);
}
Common.dc.SubmitChanges();
Can you help now please..
Regards,
Jineesh TR.
-- modified 28-Sep-12 6:31am.
|
|
|
|
|
The one important detail you left out is what do you mean by "it's not working"! That's the definition of what the problem is, not what all these little things in the code are.
What is it actually doing? What's the expected behavior? Are there any error messages?? Did you step through the code line by line and inspect the variables to make sure everything is as it should be?
|
|
|
|
|
Thank you Dave Kreskowiak,
This is the code for saving the 'asset' details. The asset details are saving in to the table TblAsset.
public static LINQtoSQLAssetMeterDataContext dc=new LINQtoSQLAssetMeterDataContext("ConnectionString");
protected override void Save()
{
if (clsTblAsset == null) clsTblAsset = new TblAsset();
clsTblAsset.AssetConditionId = cmbAssetCondition.SelectedValue.getInteger();
clsTblAsset.SerialNo = txtSerialNo.Text.getString();
clsTblAsset.ServiceTag = txtServiceTag.Text.getString();
clsTblAsset.CostCenterId = cmbCostCenter.SelectedValue.getInteger();
clsTblAsset.AssetStatusId = cmbAssetStatus.SelectedValue.getInteger();
clsTblAsset.Description = txtDescription.Text.getString();
clsTblAsset.LocationId = cmbLocation.SelectedValue.getInteger();
clsTblAsset.AssetNo = txtAssetNo.Text.getString();
if (pictBarcode.Image != null)
clsTblAsset.BarCode = barcodePict;
if (pictAsset.Image != null)
clsTblAsset.AssetPict = assetPict;
clsTblAsset.Notes = txtNotes.Text.getString();
if (clsTblAsset.AssetId == 0)
{
clsTblAsset.StockId = ucItem._Id.getInteger();
clsTblAsset.RefId = 0;
clsTblAsset.RefModule = "S";
clsTblAsset.AssetEntryDate = DateTime.Now.Date.getDateTime();
clsTblAsset.LoginId = ClsParameters.LogInId;
dc.TblAssets.InsertOnSubmit(clsTblAsset);
}
dc.SubmitChanges();
}
If the AssetId is zero, then details are inserted to the table. and if the AssetId>0, asset details are updated to the table.
Here the problem I am facing is that,
Once if we insert in to the table, all the details are inserted properly. Once if we are editing an 'asset' data and changing the value and updating the table, The data is not get updated. But no errors or exception is occuring.
Please let me know, if any one knows it.
Regards,
Jini4
|
|
|
|
|
Put a breakpoint on the first line in this Save method. Once execution hits the breakpoint, it'll stop and you can step through the code line-by-line and inspect variables up to the point. I'm pretty sure you'll find a value that's not what i't supposed to be.
|
|
|
|
|
|
Would you care to elaborate as to what the problem actually is? the exact error message (if any), which line, or how is it behaving and how do you expect it to behave.
Also, you said you were trying to update, but I see an InsertOnSubmit in your code...
|
|
|
|
|
Thank you Emmanuel Medina Lopez,
This is the code for saving the 'asset' details. The asset details are saving in to the table TblAsset.
public static LINQtoSQLAssetMeterDataContext dc=new LINQtoSQLAssetMeterDataContext("ConnectionString");
protected override void Save()
{
if (clsTblAsset == null) clsTblAsset = new TblAsset();
clsTblAsset.AssetConditionId = cmbAssetCondition.SelectedValue.getInteger();
clsTblAsset.SerialNo = txtSerialNo.Text.getString();
clsTblAsset.ServiceTag = txtServiceTag.Text.getString();
clsTblAsset.CostCenterId = cmbCostCenter.SelectedValue.getInteger();
clsTblAsset.AssetStatusId = cmbAssetStatus.SelectedValue.getInteger();
clsTblAsset.Description = txtDescription.Text.getString();
clsTblAsset.LocationId = cmbLocation.SelectedValue.getInteger();
clsTblAsset.AssetNo = txtAssetNo.Text.getString();
if (pictBarcode.Image != null)
clsTblAsset.BarCode = barcodePict;
if (pictAsset.Image != null)
clsTblAsset.AssetPict = assetPict;
clsTblAsset.Notes = txtNotes.Text.getString();
if (clsTblAsset.AssetId == 0)
{
clsTblAsset.StockId = ucItem._Id.getInteger();
clsTblAsset.RefId = 0;
clsTblAsset.RefModule = "S";
clsTblAsset.AssetEntryDate = DateTime.Now.Date.getDateTime();
clsTblAsset.LoginId = ClsParameters.LogInId;
dc.TblAssets.InsertOnSubmit(clsTblAsset);
}
dc.SubmitChanges();
}
If the AssetId is zero, then details are inserted to the table. and if the AssetId>0, asset details are updated to the table.
Here the problem I am facing is that,
Once if we insert in to the table, all the details are inserted properly. Once if we are editing an 'asset' data and changing the value and updating the table, The data is not get updated. But no errors or exception is occuring.
Please let me know, if any one knows it.
Regards,
Jini4
|
|
|
|
|
how to upload a song and retrieve the song from database..
please give any idea about on this....
|
|
|
|
|
1-Create database with table : tbSongs
guid | songname | songfile
----------------------------
guid uniuqeidentfieir
songname varchar(255)
songfile image
2-Convert your song to byte array
public static byte [] File2ByteArray (string szFileName)
{
Stream st = new FileStream (szFileName,FileMode.Open);
byte[] bit = new byte[st.Length];
st.Read(bit, 0 , (int)st.Length);
st.Close();
return bit;
}
3-Store it in tbSongs
#region Fields
private Guid _guid;
public Guid guid
{
get
{
return _guid;
}
set
{
_guid = value;
}
}
private string _songname;
public string songname
{
get
{
return _songname;
}
set
{
_songname = value;
}
}
private Byte[] _song;
public Byte[] song
{
get
{
return _song;
}
set
{
_song = value;
}
}
#endregion
#region Database
public void Insert()
{
DBConnect.DBCommand.CommandText = "INSERT INTO tbSongs VALUES (?, ?, ?)";
DBConnect.DBCommand.Parameters.AddWithValue("@guid", guid);
DBConnect.DBCommand.Parameters.AddWithValue("@songname", songname);
DBConnect.DBCommand.Parameters.AddWithValue("@image", song);
DBConnect.DBCommand.ExecuteNonQuery();
DBConnect.DBCommand.Parameters.Clear();
}
to retrive the song from database :
Find you song with guid or name and cast datareader to bytes array.
public static byte[] GetFilebytes(guid guid)
{
DBCommand = new DBCommand("SELECT songfile FROM tbsongs WHERE guid = @guid", DataBase.DBConnection);
DBCommand.Parameters.AddWithValue("@guid", guid);
byte[] filebytes = (byte[])DBCommand.ExecuteScalar();
DataBase.DBCommand.Parameters.Clear();
return filebytes;
}
4-Use File Stream or Memory Stream to Save your Song
byte[] filebites = GetFilebytes(songguid)
FileStream fs = new FileStream("c:\\mysong.mp3", FileMode.CreateNew, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(filebytes);
bw.Close();
fs.Close();
Hope this help
|
|
|
|
|
You can use a BLOB (binary large object) to store song data into the database.
This[^] might help.
|
|
|
|
|
I'v seen various posts on this and other forums about reading emails. While the C# code looks simple enough, what I'm confused on is the different 'technologies' that seem to be out there.
1) What is the difference between IMAP, MAPI, and POP3?
2) Is there a standard email message format?
Thanks!
If it's not broken, fix it until it is
|
|
|
|
|
I think a simple Google search can clarify your questions.
It depends on the Email provider or server configuration to access the emails. Most of the email services provides POP3/SMTP access to the user accounts. This standard is quite old and mostly meant for old mail clients. IMAP is a modern protocol to access emails and it too has several different versions. Google Mail supports POP and IMAP. On the other hand most of the corporate Emails runs Microsoft Exchange server and can be access with POP and Exchanges protocol.
MAPI is a properetiery API from Microsoft to access the Exchange Server and other mail protocols.
-Sarath.
Rate the answers and close your posts if it's answered
|
|
|
|
|
Kevin Marois wrote: Is there a standard email message format? Yes, see RFC 5322[^].
/ravi
|
|
|
|
|
In a C# 2008 console application, I am trying to call a java web service. I am getting the error: 'java.lang.Exception: java .lang.Exception: Please pass the correct mime type value'.
I am trying to pass an excel spreadsheet 2007 that has the extension *.xlsx. I am passing the following mine value to the web service:
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.
I have looked at urls like the following: http://filext.com/faq/office_mime_types.php to try different mine types. However none of these methods have worked.
Do you have any suggestions on what I can try next?
|
|
|
|
|
The term is not "mine type", it's "MIME type".
Even though that's the correct MIME type for an .xlsx file, I suggest you ask the maker of the web service for what it recognizes and supports. It's entirely possible that it doesn't support an .xlsx file, but maybe an older Excel format.
At this point, anyone to answer is just guessing, as are you.
|
|
|
|