|
That's because you can't do it.
There are two IP addresses involved here:
1) The "local" IP address by which you communicate to your router (or other internet gateway device) - this is likely to start with 192.168.xxx.xxx and can be changed, if you communicate with your local DHCP controller and ask it to re-assign you a new address. This is dependant on the actual kit you use for DHCP services, so there isn't a "one-stop" way to do it.
It is very unlikely that you actually want to change this IP address!
2) The internet IP address by which you communicate with websites - this will not start with 192.xxx.xxx.xxx but could start with almost anythign else.
This is probably the one you want to change to "hide" who you are from other sites. It's also the one you can't change at all!
Partly because it is shared by all devices connected to your router, so changing it would disconnect them from whatever they are doing, and mostly because it is assigned by your Internet Service Provider and may be Static (never, ever changes) or Dynamic (changes when the ISP recycles the connection). Dynamic IPs can be changed by resetting the ADSL connection, but in the case of Fibre based connections the "down time" has to be significant - hours at the least, and I have heard of days being needed to get a really new IP.
You can "sort of" change your IP by going via a internet based proxy server, but do bear in mind that they do record what you do, and may limit your activities and / or send the monitor data to various legal authorities. In addition, a proxy based system may change it once, but you will probably get the same IP the next time you use the same service.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am writing a code for loading a multiple flat file into SQL server. Each flat file has different number of columns. Below are few examples.
FlatFile1:
sampleID ; rep# ; protein ; fat ; Lactose ; TS ; SNF ; GLucose;
12334 ; 1 ; 0.23 ; 0.4 ; 0.23 ; 3.4; 4.5 ; 0.9;
FlatFile2:
sampleID ; rep# ; Water ; TNC ; protein ; TS ; SNF ; Fat;
12134 ; 1 ; 6.1 ; 2.1 ; 5.6 ; 1.3; 6.5 ; 0.4;
FlatFile3:
sampleID ; rep# ; Ph ; Fat ; protein ; TS ;
10986 ; 1 ; 6.1; 2.1 ; 5.6 ; 1.3;
10207 ; 2 ; 5.0; 1.3 ; 3.1 ; 1.45;
My Output:
sampleID rep# protein TS Fat
12334 1 0.23 3.4 0.4
12134 1 5.6 1.3 0.4
10986 1 5.6 1.3 2.1
10207 2 3.1 1.45 1.3
My C# knowldege is very basic. After doing some research I came up with some code which is like below.
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
namespace SSISDYnanic.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
{
string delimiter = Dts.Variables["User::Delimiter"].Value.ToString();
string TableName = Dts.Variables["User::TableName"].Value.ToString();
SqlConnection myADONETConnection = new SqlConnection();
myADONETConnection = (SqlConnection)
(Dts.Connections["BIReports"].AcquireConnection(Dts.Transaction) as SqlConnection);
string SourceDirectory = Dts.Variables["User::SourceFolder"].Value.ToString();
string[] fileEntries = Directory.GetFiles(SourceDirectory);
foreach (string fileName in fileEntries)
{
string columname = "";
System.IO.StreamReader file2 = new System.IO.StreamReader(fileName);
int counter = 0;
string line;
System.IO.StreamReader SourceFile =
new System.IO.StreamReader(fileName);
while ((line = SourceFile.ReadLine()) != null)
{
if (counter == 0)
{
columname = line.ToString();
columname = columname.substring(length(columname)-1,1).replace(";","")
columname = "" +columname.Replace(delimiter, ",");
MessageBox.Show(columname);
}
else
{
string query = "Insert into " + TableName +
"(" + columname + ") VALUES('" + line.Replace(delimiter, "','") + "')";
SqlCommand myCommand1 = new SqlCommand(query, myADONETConnection);
myCommand1.ExecuteNonQuery();
}
counter++;
}
SourceFile.Close();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
}
1.) Problem with the code below is it writes all the columns into the table. And the table has to have all possible columns which I can't guess because I don't know. But no matter how many columns in the flat file I know the columns I want.
If code could be modified to pick only the 5 columns in my out put that would be great other wise if I could get help fixing below that is fine too.
2.) Also other problem is in the way the flat file is it ends with a delimiter (;) which results in a insert statement that ends with a ','for example
"Insert into tablename(sampleID ,rep#,Ph,Fat,protein,TS,) values (10986, 1,6.1,2.1,5.6,1.3,)"
columname = columname.substring(length(columname)-1,1).replace(";","")
So I added this in the code which doesn't work basically trying to replace last ":" with an empty space.
SVK
|
|
|
|
|
 Something like this would work to parse the files:
public sealed class FlatFileLine
{
private sealed class MetaData
{
public readonly int? SampleID;
public readonly int? RepNo;
public readonly int? Protein;
public readonly int? TS;
public readonly int? Fat;
public MetaData(string[] fields)
{
for (int index = 0; index < fields.Length; index++)
{
string field = fields[index].Trim();
if (string.Equals(field, "sampleID", StringComparison.OrdinalIgnoreCase))
{
SampleID = index;
}
else if (string.Equals(field, "rep#", StringComparison.OrdinalIgnoreCase))
{
RepNo = index;
}
else if (string.Equals(field, "protein", StringComparison.OrdinalIgnoreCase))
{
Protein = index;
}
else if (string.Equals(field, "TS", StringComparison.OrdinalIgnoreCase))
{
TS = index;
}
else if (string.Equals(field, "Fat", StringComparison.OrdinalIgnoreCase))
{
Fat = index;
}
}
}
}
public string SampleID { get; private set; }
public string RepNo { get; private set; }
public string Protein { get; private set; }
public string TS { get; private set; }
public string Fat { get; private set; }
public static IEnumerable<FlatFileLine> ParseFile(TextReader reader, string delimiter)
{
if (reader == null) throw new ArgumentNullException("reader");
return ParseLines(ReadLines(reader, delimiter));
}
private static IEnumerable<string[]> ReadLines(TextReader reader, string delimiter)
{
string line;
while ((line = reader.ReadLine()) != null)
{
yield return line.Split(new[] { delimiter }, StringSplitOptions.None);
}
}
private static IEnumerable<FlatFileLine> ParseLines(IEnumerable<string[]> lines)
{
MetaData columns = null;
foreach (string[] fields in lines)
{
if (columns == null)
{
columns = new MetaData(fields);
}
else
{
yield return new FlatFileLine(fields, columns);
}
}
}
private FlatFileLine(string[] fields, MetaData columns)
{
if (columns.SampleID < fields.Length)
{
SampleID = fields[columns.SampleID.Value];
}
if (columns.RepNo < fields.Length)
{
RepNo = fields[columns.RepNo.Value];
}
if (columns.Protein < fields.Length)
{
Protein = fields[columns.Protein.Value];
}
if (columns.TS < fields.Length)
{
TS = fields[columns.TS.Value];
}
if (columns.Fat < fields.Length)
{
Fat = fields[columns.Fat.Value];
}
}
}
With that in place, your Main method would look something like this:
public void Main()
{
string delimiter = Dts.Variables["User::Delimiter"].Value.ToString();
string TableName = Dts.Variables["User::TableName"].Value.ToString();
string SourceDirectory = Dts.Variables["User::SourceFolder"].Value.ToString();
string query = @"INSERT INTO [" + TableName + "] (sampleID, [rep#], protein, TS, Fat) VALUES (@sampleID, @RepNo, @protein, @TS, @Fat)";
using (SqlConnection connection = Dts.Connections["BIReports"].AcquireConnection(Dts.Transaction))
using (SqlCommand command = new SqlCommand(query, connection))
{
foreach (string fileName = Directory.EnumerateFiles(SourceDirectory))
{
using (StreamReader reader = File.OpenText(fileName))
{
foreach (FlatFileLine line in FlatFileLine.ParseFile(reader, delimiter))
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@sampleID", line.SampleID ?? string.Empty);
command.Parameters.AddWithValue("@RepNo", line.RepNo ?? string.Empty);
command.Parameters.AddWithValue("@protein", line.Protein ?? string.Empty);
command.Parameters.AddWithValue("@TS", line.TS ?? string.Empty);
command.Parameters.AddWithValue("@Fat", line.Fat ?? string.Empty);
command.ExecuteNonQuery();
}
}
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
NB: "rep#" is a bad name for a column in a SQL database, because of the "#" character. If possible, you should consider changing the name to something that only uses alpha-numeric characters - for example, "RepNo".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you. It worked like a charm.
|
|
|
|
|
I am creating dynamic controls from the database in an MVC application.
I have multiple properties of a material stored in the database from which different controls are displayed. The values of these properties should be taken as user input and stored in database again.
Suppose, these controls are x number of textboxes. Then which is the best way to process these data as rows and insert it to database.
Thank you.
|
|
|
|
|
a classic database is row based, so you have to process is by row
unless all the rows have a common change
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
hi
i have this code for printing, and i need to make height the font.
how to do it ?
ev.Graphics.DrawString("MyText", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), new PointF(15,125));
thanks
|
|
|
|
|
What does "make height the font" mean?
If you want to make the font bigger, just pass a bigger point size to the constructor:
ev.Graphics.DrawString("MyText", new Font("Arial", 18, FontStyle.Bold), new SolidBrush(Color.Black), new PointF(15, 125));
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If I understand correctly, you would just have to increase the 10 in there, which is the font height, to something bigger.
I suggest to use disposable resources, like Font and SolidBrush in this case, in using-blocks, like so:
using (var arial20Bold = new Font("Arial", 20, FontStyle.Bold))
using (var solidBlack = new SolidBrush(Color.Black))
{
ev.Graphics.DrawString("MyText", arial20Bold, solidBlack, new PointF(15, 125));
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
thanks for the help,
i need only increase the height.
how to do it ?
thanks
|
|
|
|
|
The previous post showed you how to do it, use a larger number for font size.
|
|
|
|
|
Width/height ratio of a char is fixed. If you make it "higher", you also make it "wider".
You could draw the string on a canvas, and copy that part of the image to another image with the same width, larger height, and stretch it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hello i want to run a text file with my audio file how?
|
|
|
|
|
Your question makes no sense at all.
Are you saying that you want to take a text file and run it through a text-to-speech engine in the application that you're writing?
|
|
|
|
|
the sample class
public class Foo{
public string Name {get;set;}
public bool IsLocked {get;set;}
public double LockID {get;set;}
}
and i have this method
public dictionary<string, object> GetSettings()
{
return somethig;
}
then when i access it like this
var sample = new Foo();
var prop = sample.GetType();
foreach(var item in GetSettings())
{
prop.GetProperty(item.key, BindingFlags.public | BindingFlags.Instance).SetValue(prop, item.Value, null)
}
then i got an exception "Object does not match target type"
I cant find any solution on the web
I will appreciate for any advice will come
thank you
|
|
|
|
|
Means that the type which the property expects is different from the type you are putting in there.
You've got a lot going on in a single line of reflection, I'd recommend to break it up in atomic statements; first get the property and put that in a PropInfo. Check if you found it, and then assign a value. Makes debugging a lot easier.
By the looks, I'd say the the boolean and the double are being fed strings.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I just discard the reflection, i found no benefit using the reflection for that method other than writing a less code.
|
|
|
|
|
hi all, i created a login form/pos system, so far its goin good yet somehow i did something wr0ng, everything works perfectly and then all of a sudden i get a message (paste it below) yet i didnt make any changes or nothing
error: i get 2 errors and 10 warnings
------""" Could not copy "obj\Debug\login form.exe" to "bin\Debug\login form.exe". Beginning retry 1 in 1000ms. The process cannot access the file 'bin\Debug\login form.exe' because it is being used by another process. login form""""""""""---------- although it states its used by another program-it isnt any ideas?
I Checked in the task manager under processes tab / nothing there of login form.exe
|
|
|
|
|
Are you sure you haven't left something running in the background - e.g. stopping the program in the debugger and then trying to run it again?
Try closing Visual Studio and opening it again. Try Cleaning the project - or manually deleting the contents of the bin\Debug (or bin\Release) folder
|
|
|
|
|
nope , killed all processes, tried cleaning , if i restart its fixed until i debug / run it more than 2 times, so it somehow stays open while hiding itself i guess, because in the task manager theres nothing, neither in processes
|
|
|
|
|
Is it using a resource that isn't being disposed of properly?
|
|
|
|
|
im still new to most of this, how would i check to see if its using a resource thats not disposed of properly??
|
|
|
|
|
Review your code
For example, have you opened a connection to a database without using using or closing the connection when you're finished with it? Ditto using Excel/Word via interop.
The only other thing I can suggest is comment out tracts of code, prove the problem has gone away, then uncomment a section, run again ... repeat until the problem re-occurs and you will have at least located the section causing the issue.
There was a version of VS I used a few years ago that kept leaving the vhost in Task Manager - I had a pre-compile step that killed the process. The problem went away after the latest patches were applied, so make sure you have applied all of the patches (if any) for your version of VS
|
|
|
|
|
thanks ill get back to double checking right away and ill also check for available patches. thanks alot,also im using the VS 2015 RC edition if thats worth something 
|
|
|
|
|
Far more recent than the version that gave me grief In which case, check that code. Good luck
|
|
|
|
|