|
Hi sasuko and harry, would you like some light reading[^]?? :P it's a good article.
You should be able to understand how to use ADO.NET the easy way, because believe me, it's difficult.
daniero
|
|
|
|
|
So here is my issue. I am communicating to UPS via there rate web service. I am retreiving the shipping options and costs and adding listItems to a radiogrouplist control (code below). I then have a button control that fires and event to take the value of the selectedItem and pass that through a calculateShipping() function...which updates order and cost. My problem is that when I fire the button event no value is able to be retrieved. I have tried retreiving the item.Text and nothing comes through there either. Here is the unusual point. If I manually add an item before the programmatic items are added then I can get the manually added items value..but none other. Am I building the line items incorrectly? Is this an issue with the control. PLEASE HELP!
C#
Code for programmatically adding listItems to the RadioButtonList control (rbUPS):
if (us.ServiceCode == ShipCode) {
ServiceName = ServiceName.Replace("®","");
odb.UpdateTempOrderShipping (cid,
ServiceName,
us.ServiceCharge * shipments *
decimal.Parse (ConfigurationSettings.AppSettings ["ShippingMultiplier"]));
this.rbUPS.Items.Add(new ListItem( ServiceName + " ($" + Math.Round(ShipCost,2) + ")", us.ServiceCode));
ListItem selectListItem = rbUPS.Items.FindByValue(ShipCode);
selectListItem.Selected = true;
}
else
{
this.rbUPS.Items.Add(new ListItem( ServiceName + " ($" + Math.Round(ShipCost,2) + ")", us.ServiceCode));
}
Code for the button control (updateShippingBtn):
public void UpdateShippingBtn_Click(object sender, System.EventArgs e)
{
if (rbUPS.SelectedIndex > -1)
{
string upsCode = rbUPS.SelectedValue;
//Response.Redirect("test.aspx?test=" + upsCode);
Session["ShipCode"] = upsCode;
}
else
{
Session["ShipCode"] = "03"; //UPS Ground Default
}
step.Value = "2";
headlineCheckoutStep.Text = titleCheckoutStep.Text = "Confirm Your Order";
checkoutStep.ImageUrl = ConfigurationSettings.AppSettings ["SystemImagePath"] + "steptwo.gif";
stepTwoPanel.Visible = true;
stepThreePanel.Visible = false;
CustomersDB cdb = new CustomersDB();
string cid = cdb.GetCustomerID();
calculateShipping (cid);
outputStepTwo (cid);
}
WHAT AM I DOING WRONG?
|
|
|
|
|
I have a database with hundreds of stored procedures and I am sure that many of them are never called.
I know how to find dependencies within the database using the system tables but that doesn't tell me how many are called from the Visual Studio project (and if so where)
I am mulling 2 different approaches but am not really sure how to go about either...
1) FXCop somehow manages to find all the strings in a compiled assembly and tell you where abouts in the project they are. I guess this solution would be optimal as I guess it would exclude comments and such like which may slightly mess up the results. I also guess writing something like that would be pretty time consuming so would be grateful if anyone has any sample code or links to articles doing this sort of thing.
2) I also considered trying to programatically automate the Visual Studio "Find" option and found it very straightforward to get the results to appear in the FindResults Window but no obvious way to get the results into a variable to manipulate.
All ideas welcome on either approach (or if you know if something like this already exists please let me know also!)
|
|
|
|
|
Hi all, i'm trying to access files on a networked dirve using the UNC name "\\myServer\d$".
Unfortunately if i dont have a drive mapped when i try to find files on the server i get an IOException saying that the directory doesn't exist.
I found some useful comments at the bottom of an article talking about using WHScript's MapNetworkDrive method. This sounds good but i can't get it to work. Here's my code which is only slightly different from the comment on the article.
public void InvokeComMember(string member, params object[] param)
{
Type type;
Object o;
try
{
type = Type.GetTypeFromProgID("WScript.Network");
o = Activator.CreateInstance(type);
type.InvokeMember(member, BindingFlags.InvokeMethod, null, o, param);
}
catch{}
finally
{
type = null;
o = null;
}
}
The paramaters being passed in are...
InvokeComMember("MapNetworkDrive", @"\\" + serverName + @"\d$", "", false, userName, password);
serverName , userName and password are all strings that i've double checked are correct.
The exception i get is...
System.Exception: Invoke Com Error ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: The network name cannot be found.
When i type the same \\"serverName"\d$ into the run window i get a connection fine so i know the serverName variable is correct.
Anyone know either...
1. What i'm doing wrong with this or
2. Another way of getting at the files on the UNC'd server.
Cheers
Kev
-- modified at 8:49 Thursday 12th January, 2006
|
|
|
|
|
|
Yeah i found that. The example i gave was from the comments section of that article. The class used in the article requires you to provide a drive letter. The ideas used in the comments section at the bottom of the article givesa a way of doing it without using a drive letter but i can't get it to work.
All i want to do is access some files using a unc name and the relevant login cridentials.
Cheers
Kev
|
|
|
|
|
Hi,
Why doesn't this unselect?
(On MouseUp)
row = HitInfo.Row;<br />
if (dg.IsSelected(row)){this.dg.UnSelect(row);}<br />
else {this.dg.Select(row);}
I threw a messagebox in before this.dg.UnSelect(row); and I can't even get it to come up.
Thanks for any help!
Mel
|
|
|
|
|
Sorry i don't have the solution but your problem is with the mouse down and up events. When you click your mouse, in the mouse down event a cell is being selected so the row is not selected.
Making IsSelected() return false evey time.
Hope that helps you find a solution.
Cheers
Kev
|
|
|
|
|
Is there a way using .NET Generics of providing a C# equivalent to the following C++?
<pre>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
class Employee
{
public:
Employee(int id, const string& name) : _id(id), _name(name) {}
int id() const { return _id; }
string name() const { return _name; }
private:
int _id;
string _name;
};
// Employees are equal if they share the same name.
class EmployeeEqualTo
{
public:
EmployeeEqualTo(string name) : _name(name) {}
bool operator()(const Employee& employee) const
{ return employee.name() == _name; }
private:
string _name;
};
void Run()
{
vector<Employee> employees;
employees.push_back(Employee(1, "Peter"));
employees.push_back(Employee(2, "Paul"));
employees.push_back(Employee(3, "Helen"));
vector<Employee>::const_iterator it;
string match;
// Find Paul
match = "Paul";
it = find_if(employees.begin(), employees.end(), EmployeeEqualTo(match));
cout << "Name: " << it->name() << ", id: " << it->id() << "\n";
// Find Helen
match = "Helen";
it = find_if(employees.begin(), employees.end(), EmployeeEqualTo(match));
cout << "Name: " << it->name() << ", id: " << it->id() << "\n";
}
int _tmain(int argc, _TCHAR* argv[])
{
Run();
return 0;
}
</pre>
The key thing here is that we just need to define a single function object EmployeeEqualTo to find an employee that is equal to a match that we specify.
Now consider a C# generics attempt.
<pre>
class Employee
{
public Employee(int id, string name)
{
_id = id;
_name = name;
}
private int _id;
public int ID
{
get { return _id; }
}
private string _name;
public string Name
{
get { return _name; }
}
}
class EmployeeTester
{
public void Run()
{
List<Employee> employees = new List<Employee>();
employees.Add(new Employee(1, "Peter"));
employees.Add(new Employee(2, "Paul"));
employees.Add(new Employee(3, "Helen"));
Employee employee;
// Find Paul
employee = employees.Find(EmployeeEqualToPaul);
Console.WriteLine("Name = {0}, ID = {1}", employee.Name, employee.ID);
// Find Helen
employee = employees.Find(EmployeeEqualToHelen);
Console.WriteLine("Name = {0}, ID = {1}", employee.Name, employee.ID);
}
/// <summary>
/// Is employee Paul?
/// </summary>
private bool EmployeeEqualToPaul(Employee employee)
{
return employee.Name == "Paul";
}
/// <summary>
/// Is employee Helen?
/// </summary>
private bool EmployeeEqualToHelen(Employee employee)
{
return employee.Name == "Helen";
}
}
</pre>
We have to define two predicates, EmployeeEqualToPaul and EmployeeEqualToHelen to provide the same functionality. Is there a way of defining a single predicate in this case?
Kevin
|
|
|
|
|
Hi Kevin!
Just like you used a separate class to host the predicate in the C++ case, you can do the same in C#.
For example:
class EmployeeComparer
{
public static string Name;
public static bool Compare(Employee e)
{
return e.Name == Name;
}
} and then
EmployeeComparer.Name = "Helen";
employee = employees.Find(EmployeeComparer.Compare); will give you the employee with the given name.
Regards,
mav
|
|
|
|
|
Yep. That looks fine. I'd sort of thought have something similar, but having that as part of the Employee class. Yours is neater though.
Kevin
|
|
|
|
|
i've a database with this structure:
[Name]* = text
[Surname]*= text
[Address]= text
[Description] = text
[Note]= memo
[Image] = OLE OBJECT
[Number] = int32
string query = "INSERT INTO TableInformation ([Name], [Surname], [Address], [Description], [Note], [Image], [Attached], [Number]) VALUES('";
conn.Open();
OleDbCommand cmd = new OleDbCommand();
// getName(), getSurname(), getAddress() return string
query += getName() + "', ";
query += getSurname() + ", '";
if(getAddress() != "")
query += "'" + getAddress() + "', ";
else
query += DBNull.Value + ", ";
// getMemo() return string
if(getMemo() != "")
query += "'" + getMemo() + "', ";
else
query += DBNull.Value + ", ";
query += "@Image, ";
// image is byte[]
if(image != null){
cmd.Parameters.Add("@Image", OleDbType.VarBinary, (int)image.Length).Value = image;
}
else
cmd.Parameters.Add("@Image", DBNull.Value);
}
if(getValue() != "")
query += "'" + getValue();
else
query += DBNull.Value;
query += ")";
cmd.Connection = conn;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
the query when image is null is like this:
---------------------------
INSERT INTO TableInformation ([Name], [Surname], [Address], [Description], [Note], [Image]) VALUES('Sasuko', 'Divos', 'green street', 'It is good', , @Image, )
but i get a INSERT INTO error, why?
|
|
|
|
|
For security's sake you already know how to do parameters. Make ALL the values being inserted in to parameters!
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
really no, can u explain?
|
|
|
|
|
Sasuko wrote: cmd.Parameters.Add("@Image", OleDbType.VarBinary, (int)image.Length).Value = image;
}
You did this for image column - Do it for all the other values as well. This will improve the security of your application and assist in reducing the ability of a mallicious attacker getting to your database via your web application. For more information read: SQL Injection Attacks and some tips on how to prevent them[^]
I can understand someone who does not know about parameters not using them, but it is obvious you know how to add a parameter to the commnand (as you demonstrated it in your code). It seems strange to use parameters for some values but not others.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Because the fifth and sevent values are missing.
You can't put a DBNull value into a string, you have to add the text "null" to the string.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks at all you guys!
How can i protect my password for connection to the Microsoft Access Database?
Can i use Store Procedure with Access Database?
|
|
|
|
|
Hi,
How can i use variables as an old value an dnew value in String variable's Replace method like Replace(var1, var2). I tried it but it is not working.
p
|
|
|
|
|
sohne wrote: How can i use variables as an old value an dnew value in String variable's Replace method like Replace(var1, var2).
Like this:
string originalString = "I like cats.";
string oldValue = "cats";
string newValue = "dogs";
string newString = originalString.Replace(oldValue, newValue);
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Hello!
I would like to import conactinformation to Microsoft Outlook C#. I know how to do this if you want the information to be put into your regular contactlist in Microsoft Outlook. But I can't get it to be a part of "Public Folders -> All Public Folders". Here is my code:
<br />
public void exportContactToOutlook(Person contact)<br />
{<br />
Outlook.Application objOutlook = new Outlook.ApplicationClass();<br />
NameSpace outlookNS = objOutlook.GetNamespace("MAPI");<br />
MAPIFolder contactFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olPublicFoldersAllPublicFolders);<br />
<br />
<br />
Outlook.ContactItem objContact = (Outlook.ContactItem)objOutlook.CreateItem(Outlook.OlItemType.olContactItem); <br />
objContact.CompanyName = contact.CompanyName;<br />
objContact.Save();<br />
}<br />
This will only save it to the regular contactlist. I know that this code shouldn't work but what is the missing link? Any ideas?
|
|
|
|
|
How can be a transparent panel control can be created. As I tried in many ways but it is applicable to window but not to the required control (panel), as well as I also have observed that Transparency will be applicable to windows forms but not to user control. Is it so, if yes why.
Shashidhar
|
|
|
|
|
i have tried a lot but did not find any method for that
i think it's impossible
Regards,
Pramod
|
|
|
|
|
Try making a bitmap that is all one colour and setting it as the background image for your panel.
Then add the following code to the form_Load event
Bitmap bitmap = (Bitmap)pnlBackground.BackgroundImage;
bitmap.MakeTransparent(bitmap.GetPixel(1, 1));
TransparencyKey = BackColor;
You may also need to start the form minimized and then do WindowState = FormWindowState.Normal; I don't know why but sometimes this is the case.
Cheers
Kev
|
|
|
|
|
Hello,
can anyone show me a sample how to establish a GPRS connection in c# .net?
Or tell me where to look.
thanks
|
|
|
|
|
Hi,
How to start and stop windows services using c# asp.net.
Thanks
Warm Regards
Prakash-B
|
|
|
|
|