|
How would *you* go about using OleDb to perform this task?
The only thing I can think of would be to use an OleDbDataReader to walk through the sheet and build another that matches the correct format in memory and when finished, save out to the original location.
"I need build Skynet. Plz send code"
|
|
|
|
|
I assumed you knew the name of the sheet and the index of the column the data is currently in and the index of the column you wish the data was in. Then it is merely a case of using a datareader to swop the columns with a data type change in the process.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
oh, I must have described the problem wrong then...
This is contrived, but I think it traps everything:
Sheet looks like this:
ColumnA | ColumnB | ColumnC | ColumnD
1)ColumnA contains data that needs to have a substring extracted and inserted as a new column between the existing ColumnA and ColumnB.
2)ColumnC is the wrong datatype.
maybe I'm just overthinking the problem.
"I need build Skynet. Plz send code"
|
|
|
|
|
never mind...I just needed to actually start writing the code to get the juices flowing
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string foo = reader[0].ToString();
string newcolumn = foo.Substring(foo.IndexOf(":") + 1);
object[] meta = new object[reader.FieldCount];
reader.GetValues(meta);
List<string> list = meta.ToList().ConvertAll(o => o.ToString());
}
}
"I need build Skynet. Plz send code"
|
|
|
|
|
Glad to help, even if it was just to get you thinking on a different track
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Ok...another mental block:
I can read the rows in the sheet, I can access the cells from the row via an OleDbDataReader
...but how do I hook directly into a row in the Excel spreadsheet to update it once I have my update record crafted?
using (OleDbCommand command = connection.CreateCommand())
{
int idx = 0;
command.CommandText = string.Format("select * from [{0}$]", "Report_12251104");
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string foo = reader[0].ToString();
string newcolumn = foo.Substring(foo.IndexOf(":") + 1);
object[] meta = new object[reader.FieldCount];
reader.GetValues(meta);
List<object> list = meta.ToList();
list.Insert(2,newcolumn);
}
OleDbCommand update = connection.CreateCommand();
update.CommandText = "update ??what exactly?? Can I use idx to id a row by number??";
update.ExecuteNonQuery();
idx++;
}
}
"I need build Skynet. Plz send code"
|
|
|
|
|
Hi
I have a web method (see below) which accepts an integer as a parameter. I want to be able to catch the error if a paramter is not provided. I thought using catch (ArgumentException) would do the job
Is there anything else i should be doing to be able to catch errors like this ?
thanks
Simon
[WebMethod]
public DataSet GetOrganisation(int organisationId)
{
DataSet ds = new DataSet();
try
{
.....
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
WriteToLog(organisationId.ToString(), "", "GetOrganisation", ex.Message);
}
catch (ArgumentException argerr)
{
WriteToLog(organisationId.ToString(), "", "GetOrganisation", argerr.Message);
}
return ds;
}
|
|
|
|
|
huh? you can't pass anything BUT an int to that method. Its not an optional parameter.
|
|
|
|
|
Notice that it's a web method. If somebody tries to call the web method via a web service, an exception will be thrown, but it can't be caught in that method. There may be another place to catch such errors on the server-side (before the client gets an exception), but I'm not sure.
Somebody in an online forum wrote: INTJs never really joke. They make a point. The joke is just a gift wrapper.
|
|
|
|
|
You mean if somebody builds their own raw XML and calls the method directly? If you use a generated proxy class and its "out of date", the proxy class will handle the exception. Not quite sure what you are trying to accomplish.
|
|
|
|
|
I'm not trying to accomplish anything. I was just clarifying what the OP seems to be trying to get at. Seems like they want to have control over what is returned in the case that a bad request is received (e.g., return a message that details which parameters were missing from the call).
Somebody in an online forum wrote: INTJs never really joke. They make a point. The joke is just a gift wrapper.
|
|
|
|
|
As long as you pass an integer, any integer, to this method no exception will be generated.
What you can do is check for a valid range then throw an exception if the variable passed to this method doesn't fall within that range. This can be done in several ways, hard coded, using Validation Application Block or Code Contracts. It's up to you.
No comment
|
|
|
|
|
Normally, in .NET I create wrapper classes for all of my web methods.
[WebMethod]
public FooBarResult FooBar(FooBarParameters parameters){
FooBarResult result = new FooBarResult();
try{
... do work here
}
catch(Exception e1){
... Perform logic to determine how much of the exception you can return and
... assign that to the result object in a special errors property
}
}
While not perfect in any manner it lets me consistently write web methods and always know how the results are coming back. I do a lot of cross platform WS work which is a real pain because both the Java tools and the .NET tool behave differently. This pattern gives a small semblance of sanity.
|
|
|
|
|
Question doesn't make any sense.
GetOrganisation() will not be invoke unless there is a value for organisationId.
So there is no way to test in that method whether a client called it with a value or not.
If you are asking about client code that calls that method then a much more likely error scenario is a communication fault. Although it is possible to call the server such that it is unable to resolve the method that is unlikely to be a valid scenario and it isn't a scenario that will exist for long. And even then it is a problem with the client code.
|
|
|
|
|
Does anyone knows how can i get properties of an mp3 file? such as artist, album etc.
what class shold i use?
|
|
|
|
|
The best thing is to use a 3rd party library. TagLib#[^] is an open source library from Novell, and id3DotNet[^] is another open source library on SourceForge.
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
thanks
I added the TAGLIB library but i cant find the specific class i need.
|
|
|
|
|
This example assumes the MP3 file has at least one artist in the tag.
TagLib.File tagFile = TagLib.File.Create (mp3Filename);
System.Console.WriteLine ("Album = {0}", tagFile.Album);
System.Console.WriteLine ("Artist = {0}", tagFile.AlbumArtists[0]); /ravi
|
|
|
|
|
Search here on CP: there are many projects here, going back to 2002, that demonstrate how to get meta-information from .mp3 files.
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." Bjarne Stroustrop circa 1990
|
|
|
|
|
I want to write 1 extension method,it's purpose is convert 1 IEnumerable<T> to 1 ObservableCollection<T>, but i've error :
Error 5 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)
Here is my code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Data;
namespace BookStore.Helper
{
public static class ExtensionMethods
{
public static ObservableCollection<T> ToObservableCollection(this IEnumerable<T> source)
{
ObservableCollection<T> target = new ObservableCollection<T>();
foreach (T item in source)
target.Add(item);
return target;
}
}
}
|
|
|
|
|
You need to add <T> to the method name. Try this:
public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> source)
{
ObservableCollection<T> target = new ObservableCollection<T>();
foreach (T item in source)
target.Add(item);
return target;
}
Hoep this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
|
I thought this could be much simpler: in the extension:
return new ObservableCollection<T>(source); No 'foreach' needed.
Full disclosure: my first several attempts at doing this using variations of 'Select' and 'Cast' led to stack-overflow errors: so I went a-hunting and found this on StackOverFlow[^].
So, vote the SO answerer up, not this 'gofer'
best, Bill
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." Bjarne Stroustrop circa 1990
|
|
|
|
|
iam creatin c#4 wndows application
this appication creat work team meating & then send email to wrok tem members
database is published on internt not local becuase this application 'll be access from differnt people
my problem is when someone creat meating he may say it 'll repeated each week
so what i need too add new row in database for each meet week but the problem is that i can't do that from my application becasue i don't know when application open may be someone open appliction creat meet then close application & didn't open until he want to creat new meet
so i need something that work on pblished server that do that work check if new meet is new near send email to members & add new row in database
how can i do that
any help please
md_refay
|
|
|
|
|
Don't just post the same question everywhere: you waste time and effort.
Since you have posted this in Q&A[^], don't add it here as well.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|