|
i still only get the byte[0] to write out.
OdbcConnection cn = new OdbcConnection(); // assuming db connection made correction
OdbcCommand cm = new OdbcCommand();
Random r = new Random( ( int )DateTime.Now.Ticks );
OdbcParameter op;
cm.Connection = cn;
byte[] b = new byte[32];
for ( int i = 0; i < b.Length; i++ )
{
b[i] = ( byte )( r.Next() % 256 );
}
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Clear();
op = cm.Parameters.Add( "@binVal", OdbcType.Binary );
op.Direction = ParameterDirection.Input;
op.Size = b.Length;
op.Value = b;
cm.CommandText = "sp_SaveBinaryVal";
cn.Open();
try
{
cm.ExecuteNonQuery();
}
finally
{
if ( cn.State == ConnectionState.Open )
{
cn.Close();
}
}
|
|
|
|
|
Hi Everyone
I have a rtf file which is simillar to a csv file but here the delimitting character is "|".I want to read the data in rtf file to a datatable. Please some body help me
Thanks in advance
|
|
|
|
|
Hi srinivasadithya,
You can build your own RTF Converter[^] by using the TextConverter class, split any line using String.Split( '|' ) and write the tokens to a System.Data.DataTable .
Cheers,
Jani
|
|
|
|
|
Dear jani
What is the Assembly referance for rtfConverter
could you please elaborate that
Regards
|
|
|
|
|
Hi srinivasadithya,
You have to reference the Assemblies Itenso.Sys.dll , Itenso.Rtf.Parser.dll and Itenso.Rtf.Interpreter.dll . These assemblies are located in the \bin\Debug\ folder.
The sample project Rtf2Raw200x.sln demonstrates how you can extract the text from a RTF file.
Cheers,
Jani
|
|
|
|
|
can somebody explain me Asynchoronous multithreading.
Thanks in Advance...
vikas da
|
|
|
|
|
|
Thank you very much i think i got, what i was looking for ..
vikas da
|
|
|
|
|
I'm calling a method in class Bar from an instance of class Foo.
Bar needs to be able to broadcast to other objects the Foo instance. I can get the Type easily by using the System.Diagnostics.StackTrace class (I know about the low performance!) but the only way I can get the instance is to pass it as a parameter to Bar which I'd like to avoid.
Is this possible?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
can't you just use "this"?
|
|
|
|
|
this would give the Bar instance not the Foo instance
|
|
|
|
|
Couldn't the bar class just raise an event that Foo would handle?
|
|
|
|
|
The Bar class is raising an event basically on behalf of the Foo instance. Other objects will be subscribed to Bar's events, but not to the Foo instance, so I'm trying to pass the Foo instance as if it was passing itself as sender if it was raising the event itsef.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
Unfortunately Foo isn't the parent of Bar and if it were, Bar could have many differnet parents. Thanks anyway!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Sorry Dave - it's not possible (well not with .NET currently). As Bar could be called from any number of different types of classes, this just isn't possible. However, this does sound vaguely like you're trying to do something similar to the http://www.dofactory.com/Patterns/PatternMediator.aspx[^] pattern. Might that be an option instead?
|
|
|
|
|
Thanks Pete, will read that right now!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thanks for the link - I'd never looked at that pattern - I definately need to do some re-reading to 'freshen' up.
What I'm trying to do is more of a generic Observer type pattern, but using a Singleton for the subject so it's accessible by any instance of any type. Mika and I have got quite a way into this and it's pretty much working apart from this, which is a bit ugly at the moment. I've overloaded the Notify methods so that the instance can be sent as a parameter, but I'd rather make that part automated. The reference to the original instance must surely be somewhere(stack?) for the method to be able to return?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
It is on the stack, but the problem is - .NET doesn't provide any way to get to this information.
|
|
|
|
|
Actually, thats not correct. .NET provides the StackFrame object, which does exactly that...lets you walk the stack and get callers up the chain. Try this:
using System.Diagnostics;
class Foo
{
public DoSomething()
{
Bar bar = new Bar();
bar.InternalCall(new object());
}
}
class Bar
{
[MethodImpl(MethodImplOptions.NoInlining)]
internal InternalCall(object param)
{
StackFrame frame = new StackFrame(1);
MethodBase callingMethod = frame.GetMethod();
Type callingType = callingMethod.DeclaringType;
}
}
|
|
|
|
|
Hello guys
i am new to C# and i have some problem that going to make my head explode
i am stuck on this thing for a week now
i need to read data file by column not by lines
for example
i have the following data file
6, 148, 72, 35, 0, 336, 0627, 50, 2
8, 183, 64, 0, 0, 233, 0672, 32, 2
1, 85, 66, 29
1, 89, 66, 23, 94, 281, 0167, 21, 1
0, 137, 40, 35, 168, 431, 2288, 33, 2, 10, 9, 125
5, 116, 74, 0, 0, 256, 0201, 30, 1
i need to read it coulmn by coulmn and store it to arrays
for exaample the first array would be {6,8,1,1,0,5} and so on
all what i have done is read it line by line and thats not working for me
can anyone help please
|
|
|
|
|
Hmm, this problem sounds familiar
If you got the file read line by line, you have to process all the data to get it into column arrays.
I will try to post pseudocode:
1. Read the file line by line storing the values in arrays (each line is an array) and save this line in a List.
2. After reading the whole file you know how many rows you got (size of the list). Build an array with this size (i will call this array the column-array)
3. Iterate through the list of rows, check if the list contains an entry for the current column and store the value to the array (column-array[iCurRow] = curList[iCurColumn]).
That's it.
Let me know if this helps you.
Regards
Sebastian
|
|
|
|
|
thanks for you help
this is what i've done so far
i read the data in array line by line
the problem that the line lenth is not equal as i illustrate in the example
i am still stuck
public class VariableTransformation
{
private String FileName = "";
private FileReader FileReader;
private BufferedReader buffFile;
private ArrayList<string[]> attrDomainList = new ArrayList<string[]>();
private String[] item=null;
public static void main(String[] args)
{
VariableTransformation tds = new VariableTransformation();
Scanner input=new Scanner(System.in);
System.out.println("===============================================");
System.out.print("Enter the file name>> ");
String filename;
filename=input.next();
tds.fileLoad(filename);
System.out.println("===============================================");
}
public void fileLoad(String fileName)
{
String line = "";
String[] attrDomain;
FileName = fileName;
System.out.println("> Reading File..");
try {
int lineCount=0;
int size=0;
FileReader = new FileReader(FileName);
buffFile = new BufferedReader(FileReader);
try {
while((line = buffFile.readLine()) != null)
{
item = line.split(",");
size=item.length;
attrDomain=new String[size];
for (int i = 0; i < item.length; i++) {
attrDomain[i]=item[i];
}
attrDomainList.add(attrDomain);
lineCount++;
}
printData(attrDomainList);
System.out.println("> Finish File Reading.");
System.out.println("Number of Lines>> "+lineCount);
System.out.println("===============================================");
}
catch (IOException e) {
System.out.println(e.getStackTrace().toString());
System.out.println("# Error while reading file .");
}
finally
{
try {buffFile.close();} catch (IOException e) {e.printStackTrace();}
try {FileReader.close();} catch (IOException e) {e.printStackTrace();}
}
} catch (FileNotFoundException e) {
System.out.println("> Error. Target File Don't exist.");
e.printStackTrace();
}
}
private void printData(ArrayList<string[]> dataFile )
{
int Counter=0;
for (int i = 0; i < dataFile.size(); i++) {
System.out.print("["+(++Counter)+"] ");
for (int j = 0; j < dataFile.get(i).length; j++) {
System.out.print(dataFile.get(i)[j]+" ");
}
}
}
}
|
|
|
|
|
Okay, so you have to check if the line exists or not. I will try to provide code (beware: not tested).
public void fileLoad(String fileName) {
int iMaxColumnCount = 0;
...
while((line = buffFile.readLine()) != null)
{
item = line.split(",");
size=item.length;
if(size > iMaxColumnCount)
iMaxColumnCount = size;
...
}
private List<string[]> TransformData(ArrayList<string[]> aData, int iMaxColumnCount) {
List<string[]> aTransformed = new List<string[]>();
for(int iCurColumn = 0; iCurColumn < iMaxColumnCount; iCurColumn++) {
string[] aValues = new string[aData.size()];
for(int iCurRow = 0; iCurRow < aData.size(); iCurRow++) {
if(aData[iCurRow].length > iCurColumn) {
aValues[iCurRow] = aData[iCurRow][iCurColumn];
}
}
aTransformed.Add(aValues);
}
return aTransformed;
}
That's it. The trick is to count the maximum column count during the file read. Then we can use this number to transform the input.
Pls let me know if this helps you.
Regards
Sebastian
|
|
|
|
|
yeah thats work
thaaaaaaaaaaaaaaaaaaaaaaaaank you so much you really helped me sooooooooooooooo much , i dont know how to thank you really
god bless you
|
|
|
|
|