|
You have to specify which parts of the string that can vary, and how. For example, the repeated part "variable" in your example, is that always the specific word "variable", or could it be anything?
If you have an actual example of some real data, that could help when trying to understand what you are trying to do.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
well the input could be anything.
the only difference between the two lines is, one has an additional "1" at the end of every fieldname. so if you remove the last "1" from the second line, then you will get the other.
e.g.
name, address1, address2, postalcode, city, phone_1, phone_2
name1, address11, addrress21, postalcode1, city1, phone_11, phone_21
So as you might have realized the second line is the first one with an additional "1" at the end of each entry.
i guess meanwhile i found a solution to this problem:
first check if every entry ends with 1, then it's the of the second type.
if it is of the second type, then remove the last "1" by using Substring with the whole string without the last character (length-1).
The last operation will change name1 to name and so on.
But if the first operation returns, not every item has a "1" at it's end, then its of type line 1 and nothing has to be done.
in code its something like
string[] Checkforcolorsign (string[] input)
{
int counter = 0;
int i = 0;
while (i < input.length - 1)
{
if (input[i].EndsWith("1"))
{
counter++;
}
}
if (counter == input.length)
{
for(i=0; i < input.length - 1; i++)
{
input[i] = input[i].SubString(0, input[i].Length - 1);
}
}
return input;
}
Maybe this code will illustrate what I originally wanted to ask. I hope this code really does what I expect it to.
so if the input is e.g.
name1, address11, addrress21, postalcode1, city1, phone_11, phone_21
then the final result should be
name, address1, address2, postalcode, city, phone_1, phone_2
|
|
|
|
|
As far as I can tell, the code will work just fine. You don't have to return the array, though. You are changing the items in the array.
void Checkforcolorsign (string[] input) {
int counter = 0;
foreach (string s in input) {
if (s.EndsWith("1")) {
counter++;
}
}
if (counter == input.length)
for (int i = 0; i < input.length - 1; i++) {
input[i] = input[i].SubString(0, input[i].Length - 1);
}
}
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Assuming you parse the variable names into a string array, then for each
element of the array examine the last character. If is numeric then
examine the next to last character. If that character is also numeric
then strip the last character.
Of course this assumes that your color info is only a single digit.
|
|
|
|
|
that was an idea i already had, but it did not work.
e.g. if the input is of this kind
name1, address11, address21, postalcode1, city1
and the other line (without the colorsign "1" added) looks like
name, address1, address2, postalcode, city
it would work for the address elements but not for the other ones.
i already posted some code which came to my mind when thinking about it without sitting in front of the comp.
i have to check the syntax and if it works, meaning if it changes the line with the "1"s and doesn't change the line without. because that's what I want to do.
the "task" is to read fieldvalues because i do have something like
name|address1|address2|postalcode|city
Mr. X, nowhere, here and there, 1234, noname city
name1|address11|address21|postalcode1|city
.....
but the two lines could be the otherway round as well, meaning
name1|address11|address21|postalcode1|city
Mr. X, nowhere, here and there, 1234, noname city
name|address1|address2|postalcode|city
and because every datafieldline is the same like the associated valuelines (the position of the fields not the values!), i do only read the first fieldline and use the indexes for every dataline.
the fieldvalues are used for further operations (the ones without the "1" at the end). that's why i have to remove it.
|
|
|
|
|
OK, I have been searching high and low trying to find an actual example of how to do this, and have been coming up empty.
I have created a word addin project,i added a ribbon control. I even added button, however, i have not been able to make the command for the button interact with the word document.
Does anyone either know how to do this, or at least point me to a tutorial?
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
|
Is there a standard method for storing a user's username/password somewhere safe, or do I manually have to encrypt it somehow?
|
|
|
|
|
benjymous wrote: Is there a standard method for storing a user's username/password somewhere safe,
No, there is no "safe". One optimal approach is to store hash values, like using SHA1, and the next time they enter them you hash again and verify the hash matches the stored hash. In that approach you are not responsible for securing any information.
That said if you have a requirement like emailing them their password then that won't work. If you need to encrypt data some engines might do that for you like SQL Server, otherwise if you need to do it yourself see the System.Security namespace.
Also if you need to do it yourself it might pay to study some modern material on the current state of "Security" so that you can apply that to using the BCL libraries supplied.
led mike
|
|
|
|
|
Usually you just save the password hash (MD5, SHA), optionally with a salt
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
Wrong board, you have to post on ASP.NET board.
I Love T-SQL
|
|
|
|
|
Hello,
I have the following function, which is returning dataset from any of the desired identical databases. For some reason, I get exception "Must declare parameter @id"
public DataSet GetCustomerDevices(int nCustomerID, int nDatabaseID)<br />
{<br />
svcMSSQL mssql = new svcMSSQL();<br />
DataSet dsDevices = new DataSet();<br />
<br />
try<br />
{<br />
SqlConnection sqlConn = (SqlConnection)mssql.CreateConnection(clsConnStr.GetConnectionString());<br />
<br />
string strDatabase = GetDatabaseName(nDatabaseID);<br />
<br />
SqlCommand sqlCmd = (SqlCommand)mssql.CreateCommand("SELECT ColNo1, ColNo2, ColNo3 FROM "+strDatabase+".dbo.tblClientProc WHERE PartnerCode=@id ORDER BY ColNo1 ASC", sqlConn);<br />
sqlCmd.Parameters.AddWithValue("@id", nCustomerID.ToString());<br />
sqlCmd.Parameters["@id"].SqlDbType = SqlDbType.Int;<br />
<br />
foreach (SqlParameter param in sqlCmd.Parameters)<br />
{<br />
clsDebug.WriteString("Param name: " + param.ParameterName + ", Param Type: " +param.SqlDbType.ToString()+ ", value is: " + param.Value);<br />
}<br />
<br />
SqlDataAdapter sqlAdapter = (SqlDataAdapter)mssql.CreateDataAdapter(sqlCmd, sqlConn);<br />
sqlAdapter.Fill(dsDevices);<br />
<br />
sqlCmd.Dispose();<br />
sqlAdapter.Dispose();<br />
sqlConn.Dispose();<br />
}<br />
catch (Exception e)<br />
{<br />
clsDebug.ReportError(e.Message);<br />
}<br />
return dsDevices;<br />
}<br />
Here is output of the clsDebug.WriteString function:
Method: GetCustomerDevices
File:
Line: 63
Msg: Param name: @id, Param Type: Int, value is: 2762
Any help is appreciated
|
|
|
|
|
SqlCommand sqlCmd = (SqlCommand)mssql.CreateCommand("declare @id as int set @id = "+ nCustomerID.ToString()+ " SELECT ColNo1, ColNo2, ColNo3 FROM "+strDatabase+".dbo.tblClientProc WHERE PartnerCode=@id ORDER BY ColNo1 ASC", sqlConn);
I Love T-SQL
|
|
|
|
|
I thought of that solution, but I think that the query should work the way it is written. I have an option to add stored procedure, which would also be some sort of solution.
My question is why the query does not work as it is presented, moreover, why even though that I get information from the debugger that the parameter has been created, is of the correct type and contains proper value, the error presented is "must declare variable", which according to my understanding means that the query is not passed correctly between my application and the server.
Thanks for the reply!
|
|
|
|
|
then declare varialbe and use your SQL query.
I Love T-SQL
|
|
|
|
|
I am trying to pass parameter, not variable.
|
|
|
|
|
SqlCommand sqlCmd = (SqlCommand)mssql.CreateCommand("SELECT ColNo1, ColNo2, ColNo3 FROM "+strDatabase+".dbo.tblClientProc WHERE PartnerCode=@id ORDER BY ColNo1 ASC", sqlConn);<br />
sqlCmd.Parameters.AddWithValue("id", nCustomerID.ToString());
I Love T-SQL
|
|
|
|
|
Wait! Isn't that the code the OP started out with?
|
|
|
|
|
Deian wrote: sqlCmd.Parameters.AddWithValue("@id", nCustomerID.ToString());
Don't all ToString() on nCustomerID
Also, it is good practice to put the calls to Dispose in a finally block so that they get called even if an exception is thrown. At the moment, the objects won't be disposed when the exception is thrown.
Other than that I don't really see much wrong with the code.
|
|
|
|
|
Yes I will dispose objects in finally block, this is just a test function. Too sad nobody could reproduce my parameter problem.
|
|
|
|
|
Sometimes when that happens to me and I just simply cannot see what is wrong with a method then I tear down the method so it has nothing in it, go and get something to drink (anything to get away from the code for 5 to 10 minutes) come back and start from scratch on that method. Often that helps. And often the code is also better quality as a result too.
|
|
|
|
|
Well, I did that last night
I've traced the problem to my working stations, since sql profiler shows that query arrives with "... WHERE col=@param". IDE is not throwing an exception that parameter is missing, actually it is there. What I will do (in order to get going) is to construct dynamic queries and pass them directly, untill I find a solution.
Thank you for the reply!
|
|
|
|
|
Hello all,
I am having an annoying little problem with accessing an underlying row in a datatable which is being displayed in a datagridview.
I need to get hold of the ID column in the DataSource, however it is one of the columns I am not displaying to the user in the DataGridView. I can then fire a stored procedure to delete the correct row from the SQL database.
How do i access the row which is currently selected in the DataSource? I know about SelectedRows[] but it doesnt contain my ID column.
Thanks in advance...
modified on Tuesday, April 22, 2008 10:18 AM
|
|
|
|
|
when you select row from datagridview then save ID value in one label,use labels value to delete your data based on last selected ID on datagridview.
I Love T-SQL
|
|
|
|
|