public class RegistrationClass
{
SqlConnection myConnection = new SqlConnection("Data Source=MOE-PC\\SQLEXPRESS;Initial Catalog=db_University;Integrated Security=True;Pooling=False");
ConnectionClass con = new ConnectionClass();
int ID , i;
String fullName, motherName, gender, placeOfBirth, email, phone, adress, schoolDegree, languages, highSchool, faculty, major;
public void setValues (String fullName1,String motherName1,String gender1,String placeOfBirth1,String email1,String phone1,String adress1, String faculty1,String major1,String schoolDegree1,String languages1,String highSchool1)
{
fullName = fullName1;
motherName = motherName1;
gender = gender1;
placeOfBirth= placeOfBirth1;
email =email1;
phone= phone1;
adress =adress1;
faculty =faculty1;
major =major1;
schoolDegree =schoolDegree1;
languages =languages1;
highSchool = highSchool1;
}
This is the webform on register button click
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button_Register_Click(object sender, EventArgs e)
{
string lang = "";
Classes.RegistrationClass R = new Classes.RegistrationClass();
R.setValues(txt_Name.ToString, txt_MotherName.ToString, dropDown_Gender.ToString, dropDown_POB.ToString, txt_Email.ToString, txt_Phone.ToString, txt_Adress.ToString, DropDown_Faculty.ToString, DropDown_Major.ToString, dropDown_SchoolDegree.ToString, txt_Name.ToString, txt_HighSchool.ToString);
Here is the error:
The best overloaded method match for 'CCharpApp.RegistrationClass.setValues(string,string,string,string,string,string,string,string,string,string,string,string)' has some invalid arguments.
This can also happen when a dynamic variable is passed into the method as an argument. The compiler compiles without an error, there can be an execution error.
txt_Name.ToString resolves to a method group that refers to the ToString method. It doesn't call ToString. To do that you would need to write txt_Name.ToString(). Having said that, you don't want to do that either. The ToString method of TextBox does not return the text of the control. The Text property is how you get the text, so you want to write: txt_Name.Text.
Finally, you should avoid functions with so many arguments. It makes it much harder to try to determine what's wrong when you have the error that you are seeing when there are so many arguments; there are just so many ways that it could be off. Instead RegistrationClass should simply have properties of each of those values, and then the caller can set each property individually. This will be quite a lot easier to work with.
i had a same issue, solved as following.
dynamic postdata = new ExpandoObject();
postdata.player_name = player;
postdata.bidder_id = bidder;
postdata.bid_price = price;
postdata.status = "Sold";
Related
I have properly overwrite commit in InstallerSetup.cs I do not wish to write the user entered value to app.config but rather I want to pass the string Context.Parameters["TESTPARAMETER"]; to another class in form1.cs on load function. I tried string test = InstallerSetup.Context.Parameters["TESTPARAMETER"];
but getting InstallerSetup.Context is null. Please Help.
InstallerSetup.cs
public static string SQLSERVERNAME = "";
public static string HMSTENANTDB;
public static string SQLLOGIN;
public static string SQLPASSWORD;
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
try
{
SQLSERVERNAME = Context.Parameters["SQLSERVERNAME"];
HMSTENANTDB = Context.Parameters["HMSTENANTDB"];
SQLLOGIN = Context.Parameters["SQLLOGIN"];
SQLPASSWORD = Context.Parameters["SQLPASSWORD"];
}
catch (Exception e)
{
MessageBox.Show("Failed to update the application configuration file : " + e.Message);
base.Rollback(savedState);
}
}
from1.cs
InstallerSetup InsSetup = new InstallerSetup();
string Vsqlserver = InsSetup.Installers.Count.ToString();
string Vtenant = "";
if (InsSetup.Context != null)
{
Vtenant = InsSetup.Context.Parameters["HMSTENANTDB"];
}
else
{
Vtenant = "context is null";
}
As far as I can tell, the issue is that the property values are not being passed into the custom action. That would be the most obvious explanation. A commentfrom the poster says:
"passed those parameters to the custom action...................................... SQLSERVERNAME = Context.Parameters["SQLSERVERNAME"];
etc...
//................there is only these 4 lines in my custom actions"
which is essentially repeating the code that was previously posted.
This is NOT passing the values into the custom action. This is retrieving values which must already have been passed into the custom action.
Assuming that the custom action has been correctly added to (typically) the install nod of the custom action, and also assuming that the property names are in a TextBoxes dialog in the install, the values must be passed in to the custom action via the CustomActionData settings. To use one example, the CustomActionData setting must be something like:
/SQLSERVERNAME=[SQLSERVERNAME]
or /SQLSERVERNAME=[EDITA1] if EDIOTA1 is being used because that's the default property name.
However there is no reference to the TextBoxes (or any other) install dialog in the original question, so it's not really clear where the value of (say) SQLSERVERNAME is supposed to come from. It may be passed in on the msiexec command line, for example.
I was very excited to try out the new feature in VS 2012 ultimate that allows you to run whole load tests with coded web tests.
Unfortunatly, I've ran into a bit of a problem. While trying to debug a web test I've generated (and edited afterwards), I keep getting an NullReferenceException on a simple declaration line. I simply cannot wrap my head around why this occurs. Here's the code:
[Priority(0)]
public class CreateSessionCoded : WebTest
{
public string[] SessionID;
public string[] SessionTime;
public string[] CreatedTime;
public CreateSessionCoded()
{
this.Context.Add("Parameter1", "");
this.PreAuthenticate = true;
}
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
//string CurrentITR = this.Context.WebTestIteration.ToString();
SessionID[this.Context.WebTestIteration] = Guid.NewGuid().ToString();
SessionTime[this.Context.WebTestIteration] = System.DateTime.UtcNow.ToString();
CreatedTime[this.Context.WebTestIteration] = System.DateTime.Now.ToString();
...
The code goes on, but the part where I get the NRE is at the last two lines where I try to assign values to my SessionTime and CreatedTime parameters.
It doesn't happen when assigning to the SessionID, so it's not about the WebTestIteration in any way. It also happens if I try to assign a different string (any casual string such as, say, "blabla") to the same parameters.
I'd really appreciate any help! Thanks in advance! :)
You define three arrays:
public string[] SessionID;
public string[] SessionTime;
public string[] CreatedTime;
But, they aren't initialized before you attempt to use them.
Basically, you are doing this:
string[] foo;
foo[1] = "bar";
And you need to do this:
string[] foo = new string[10]; // sized appropriately
foo[1] = "bar";
i am trying to output a log of methods and their actions if taken and results into a "MyAppLog_ListView" the columnsHeaders of the lisftview Are
Record#______MethodName__________MethodsOutput
1 ______GetCurrentTime______success(21:10)
2 ______DoSplitString_______faild(not in right Format)
3......................................etc'...
this helps me debuging my program as it's over 1500 lines of code and atleast for me
it's getting a little too complex , the question is what is the right way to store methods name in a string
public void MyMethod()
{
do stuff
if (comleted) MyAppLog_ListView_AddRecord(string for the methods name, outputSucces)
else if (faild) MyAppLog_ListView_AddRecord(string for the methods name, outputFail)
}
how do i get MyMethod().Name to store in a string ?
ReEdit :
As to SidAhmeds Answer :
public void MyMethodName()
{
do stuff
string Mnam = MethodBase.GetCurrentMethod().Name;
if (comleted) MyAppLog_ListView_AddRecord(Mnam , outputSucces);
else if (faild) MyAppLog_ListView_AddRecord(Mnam , outputFail);
}
Or you could use reflection to do it :
System.Reflection.MethodBase.GetCurrentMethod().Name;
StackTrace st = new StackTrace();
var methodName = st.GetFrame(0).GetMethod().Name;
public void FindCityName()
{
string url = "http://maps.google.com/maps/geo?q=39.920794,32.853902&output=json&oe=utf8&sensor=true&key=MYKEY";
var w = new WebClient();
Observable.FromEvent<DownloadStringCompletedEventArgs>(w, "DownloadStringCompleted").Subscribe(r =>
{
var deserialized = JsonConvert.DeserializeObject<RootObject>(r.EventArgs.Result);
string s = deserialized.Placemark[0].AddressDetails.Country.SubAdministrativeArea.Locality.LocalityName;
/// setCity() and City=s produce the same thing
setCity(s);
City = s;
//foreach (var item in deserialized.Placemark)
//{
// //MessageBox.Show(item.AddressDetails.Country.SubAdministrativeArea.Locality.LocalityName);
// City = (string)item.AddressDetails.Country.SubAdministrativeArea.Locality.LocalityName;
//}
//Problem here >>>>>
////MessageBox.Show(City);
});
w.DownloadStringAsync(new Uri(url));
}
Problem:
I am working on a windows phone 7 application and I need to find the "City Name" from GPS coordinates in order to move forward...
I found the code above on the internet and tried it. I can see the city name by using these codes(Message.Box(City) show exactly what I want, the city name). However, this line of code
deserialized.Placemark[0].AddressDetails.Country.SubAdministrativeArea.Locality.LocalityName;
which gives me the city name seems to give a volatile string value.
For example, I created a method which assigns the value of string variable "s" to the string field of my class, name City. If I try to get the City's content after calling FindCityName() method, I see that City's content is not updated.
Again, same thing happens then I call the code line under the comment "Problem here >>>>>" that MessageBox.Show(City) shows nothing new...
Can someone explain me the reason of my problem?
you put this question on my blog as well, but I will answer it here. I feel a bit responsible for putting up the sample code in the first place ;-)
I am going to assume the class containing your code looks like this:
public class MyClass
{
private void MyMethod()
{
FindCityName();
MessageBox.Show(City);
}
private void FindCityName()
{
// Code omitted - see your question
}
private string City;
}
There is nothing volatile about the string. Your problem is asynchronicity. If you look carefully you will see that I use an observable that fires when the DownloadStringCompleted is fired. The code inside Observable.Event is only called when the download is finished but that happens asynchronously. But what I assume you do is call the FindCityName method and then directly trying to access results like I show in the MyMethod method. That's like directly wanting the result after firing the request. The results are not in yet! It's like a web page downloading - it takes a while. You can fix that with a callback, something like this:
public class MyClass
{
private void MyMethod()
{
FindName();
}
public void FindCityName()
{
string url = "http://maps.google.com/maps/geo?q=39.920794,32.853902&output=json&oe=utf8&sensor=true&key=MYKEY";
var w = new WebClient();
Observable.FromEvent<DownloadStringCompletedEventArgs>(w, "DownloadStringCompleted").Subscribe(r =>
{
var deserialized = JsonConvert.DeserializeObject<RootObject>(r.EventArgs.Result);
City = deserialized.Placemark[0].AddressDetails.Country.SubAdministrativeArea.Locality.LocalityName;
DoneDownloading();
});
w.DownloadStringAsync(new Uri(url));
}
private string City;
private void DoneDownloading
{
MessageBox.Show(City);
}
}
Does that help?
I would recommend you to use this Google Map API
http://maps.googleapis.com/maps/api/geocode/json?latlng=39.920794,32.853902&sensor=true
And once you get JSON response in your request. You can parse easily with NEWTONSOFT for wp7
WebClient wc = new WebClient();
var json = (JObject)JsonConvert.DeserializeObject(wc.DownloadString(url));
var locality= json["results"]
.SelectMany(x => x["address_components"])
.FirstOrDefault(t => t["types"].First().ToString() == "locality");
var name = locality!=null ? locality["long_name"].ToString() : "";
For security reasons, I don't want specific method to receive non-programmer or non-compiler time strings, how could I do this?
readonly String OK_STR = "some text";
String BAD_STR = "another text";
public void SetSecureStr(String str)
{
//Use the string for security purpose
}
//Somewhere in the code
SetSecureStr(OK_STR); //Accepted
SetSecureStr(OK_STR + "Programmer passed this staticlly!"); //Accepted (If not possible to implement, forget about it)
SetSecureStr(BAD_STR); //Throw exception, BAD_STR is modifiable
SetSecureStr(OK_STR + untrustedVar); //Throw exception, concatenation with modifiable
SetSecureStr(String.Format("{0}", OK_STR)); //Throw exception, not const
It may be better to whitelist against things inside your ability to control, such as enums or local constants (or a local whitelist from configuration data if the list isn't fixed ahead of time).
As a rough check, you could check whether it is interned, since all literals will be interned automatically via ldstr; but note you can explicitly intern too, so this isn't 100% safe.
And of course, in any event with the question as asked, if that string happens somewhere else as a literal (unconnected to this code) it would still be trusted. I suggest a whitelist is safer...
A whitelist could be as simple as:
private static readonly HashSet<string> whiteList = new HashSet<string> {
"good", "more good"
};
... check via whiteList.Contains(s)
but note that this is still mutable at runtime (via reflection if necessary).
Instead of accepting string values, number all your strings, and pass the number:
string[] good_strings = {"some text"};
public void SetSecureStr(int stringno)
{
string s = good_strings[stringno];
}
Computed strings won't be supported with that approach.
I came finally with a solution which is hybrid between the two previously proposed answers:
public class SqlQuery
{
private SqlQuery() { }
private static UInt32 sqlQueriesCount = 0;
public static UInt32 INBOUND_UPDATE_CALLBACK_NUM = sqlQueriesCount++;
public static UInt32 INBOUND_UPDATE_DEST_ADDR_SUBUNIT = sqlQueriesCount++;
public static UInt32 INBOUND_UPDATE_DEST_BEARER_TYPE = sqlQueriesCount++;
//...etc
private static readonly Dictionary<UInt32, String> queries = new Dictionary<UInt32, String>
{
{SqlQuery.INBOUND_UPDATE_CALLBACK_NUM, "UPDATE inbound SET callbackNum = ? WHERE id = ?"},
{SqlQuery.INBOUND_UPDATE_DEST_ADDR_SUBUNIT, "UPDATE inbound SET destAddrSubunit = ? WHERE id = ?"},
{SqlQuery.INBOUND_UPDATE_DEST_BEARER_TYPE, "UPDATE inbound SET destBearerType = ? WHERE id = ?"},
//...etc
};
public static String GetQueryText(UInt32 queryKey)
{
String query = null;
if (SqlQuery.queries.TryGetValue(queryKey, out query) == false)
{
throw new ArgumentOutOfRangeException(String.Format("Query must be paramerized query stored within SqlQuery class, provided queryKey: {0}", queryKey));
}
return query;
}
}
Usage:
OdbcCommand cmd = new OdbcCommand(SqlQuery.GetQueryText(SqlQuery.INBOUND_UPDATE_CALLBACK_NUM), con);