|
Hej, the Array litere is zero based, so that the index must always be smaller that the length. But your for loop starts at 0 and ends at the length:
for (int i = 0; i <= litere.Length; i++)
So instead of using <= you must use < .
|
|
|
|
|
Hello Everyone,
I want to create PPPoE Connection.
I do this code but it doesn't work and i use the library DotRas ();
When I run the code the error appear in the line:
(RasEntry entry = RasEntry.CreateBroadbandEntry("osama",RasDevice.GetDeviceByName("(PPPoE Osama)",RasDeviceType.PPPoE)); )
and the error is: Value cannot be null.Parameter name: device
The is the Code...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DotRas;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string path;
path = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);
using (RasPhoneBook pbk = new RasPhoneBook())
{
pbk.Open(path);
RasEntry entry = RasEntry.CreateBroadbandEntry("osama",RasDevice.GetDeviceByName("(PPPoE Osama)",RasDeviceType.PPPoE));
pbk.Entries.Add(entry);
}
using (RasDialer dialer = new RasDialer())
{
dialer.EntryName = "Your Entry";
dialer.PhoneBookPath = path;
dialer.Credentials = new System.Net.NetworkCredential("User", "Password");
dialer.Dial();
}
}
}
}
If there is another way please tell me how.
-*-*-*-*-*-*-*-*-*
To Be Or Not To Be
(KARFER)
-*-*-*-*-*-*-*-*-*
modified 28-Mar-15 10:19am.
|
|
|
|
|
Hi, any one know how to implement Mobile agent in C#?? Am using Mobile agent to collect the data from sensor nodes.
Thanks
|
|
|
|
|
You already posted this question below; please post once only.
|
|
|
|
|
Dear Experts,
I want to define a global variable for Database Connection variable in C# that can be accessed from any procedures in Project.
I see this in VB but in C# I cant do it.
Your help is highly appreciated.
Regards,
|
|
|
|
|
C# doesn't have global variables: the closest you can come is to create a static property of a Database class and use that:
class Database
{
public static SqlConnection Connection { get; private set; }
public void Create(string strConnect)
{
Connection = new SqlConnection(strConnect);
Connection.Open();
}
} But personally, I wouldn't do that - it encourages you to maintain a connection for teh life of the application which is a pretty poor practice. It also means that you only get one connection, so some operations are not possible - any INSERT or UPDATE while processing a SqlDataReader for example. I'd create the connections as I need them, inside a using block so that they are closed and disposed when I'm done.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You never should create a variable for database connection in a global scope. It would consume resources even where you do not need a database connection. Such as, when user is not authenticated, and you're showing him a view (or a dialog box) to tell him that he cannot connect to the database for query purposes, but in the background database would be connected already. Which won't be a good usage of your logic or resources.
It would be better to create this variable, inside the function where you need it. Connection pooling would take care of the underlying connection maintenance for your application so that you won't get a delay for connecting to the database server.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you Sir, good notes.
Appreciated your support
|
|
|
|
|
Hi, any one know how to implement Mobile agent in C#?? Am using Mobile agent to collect the data from sensor nodes.
Thanks
|
|
|
|
|
Hi Team ,
Is there some thing like this possible in C#
public enum Alphabet
{
ABC = "A",
ABC = "AB",
DEF = "D",
DEF = "DE"
}
class Program
{
static void Main(string[] args)
{
var temp = Alphabet.ABC;
}
}
|
|
|
|
|
No - enums have to be of one of the integer types. Also you can't define multiple members of the same name like you did there (ABC, ABC, DEF, DEF). You could use a static class instead:
public static class Alphabet
{
public static readonly string A = "A";
public static readonly string AB = "AB";
}
|
|
|
|
|
Thank you very much for your quick response !!!
Kod.
|
|
|
|
|
Yes, there are some things like that.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
If so please help me understand ,i goggled a lot but i could not able to find.
Thanks
Kod.
|
|
|
|
|
Sacha's suggestion would be easier to work with. Alternatively, you could add an attribute to the enum-value. See the DisplayNameAttribute[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I'm trying to make a small program in c#, that will downsample image to specified amount of colors (using K-means). Then, user will be able to hide\show colored areas(clusters) in image. I've implemented image clustering algorithm and I also have info about main colors, but how to implement show/hide color function? Example below
for this moment program only simplifies image (in this example 5 colors)
http://s1.postimg.org/olgtkizu7/image1.jpg[^]
this is what I want to have
http://s17.postimg.org/wbc522yrz/image2.jpg[^]
|
|
|
|
|
How would you "show/hide" a color? What do you expect to see in its place?
If you have a 16-color bitmap, simply upscale it to 32-bit depth and let the user adjust the palette of the colors of the bitmap. That would replace it with another color.
If you mean "hide" as in making it transparant, there's this thing called opacity. It usually uses a predefined color to denote what area's should be transparent.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I get some source codes from a textbook and rewrite them making a small system. It can CRUD user. Now I find it low efficency for coding. For example, UserDAL contains a lot of SQL scripts and they are easy to make error. UserBLL is too simple. I do not know how to improve coding efficiency. Could you give me any advices ?
The following is UserDAL source code, I intend to post UserBLL and UserModel source code but code-project remind me too long:
public class UserDAL
{
SQLHelper db = new SQLHelper();
public DataTable SelectAllUser()
{
string sql = @"SELECT [UserID],[Password],[Name],[Sex],[Phone]," +
"[Tutor],[DptName],[College],[University]," +
"[Major],[EnrollYear],[Cntnt] " +
"FROM [TrainingExam].[dbo].[ExprmntUser]";
return db.GetDataTable(sql);
}
public int InsertUser(UserModel user)
{
string sql = @"INSERT INTO [TrainingExam].[dbo].[ExprmntUser] VALUES(" +
"@UserID, @Pass, @Name, @Sex, @Phone, @Tutor, @DptName, @College, @University, @Major, @EnrollYear, @Content)";
SqlParameter[] parameters =
{
new SqlParameter("@UserID", user.UserID),
new SqlParameter("@Pass", user.Pass),
new SqlParameter("@Name", user.Name),
new SqlParameter("@Sex", user.Sex),
new SqlParameter("@Phone", user.Phone),
new SqlParameter("@Tutor", user.Tutor),
new SqlParameter("@DptName", user.DptName),
new SqlParameter("@College", user.College),
new SqlParameter("@University", user.University),
new SqlParameter("@Major", user.Major),
new SqlParameter("@EnrollYear", user.EnrollYear),
new SqlParameter("@Content", user.Content)
};
return db.ExecuteNonQuery(sql, parameters);
}
public int DeleteUser(UserModel user)
{
string sql = @"DELETE FROM [TrainingExam].[dbo].[ExprmntUser] WHERE UserID=@UserID";
SqlParameter parameter = new SqlParameter("@UserID", user.UserID);
return db.ExecuteNonQuery(sql, parameter);
}
public int UpdateUser(UserModel user)
{
string sql = @"UPDATE [TrainingExam].[dbo].[ExprmntUser] SET UserID=@UserID, Name=@Name, Sex=@Sex, Phone=@Phone, EnrollYear=@EnrollYear, " +
"Tutor=@Tutor, Major=@Major, DptName=@DptName, College=@College, University=@University, Content=@Content " +
"WHERE UserID=@UserID";
SqlParameter[] parameters =
{
new SqlParameter("@UserID", user.UserID),
new SqlParameter("@Name", user.Name),
new SqlParameter("@Sex", user.Sex),
new SqlParameter("@Phone", user.Phone),
new SqlParameter("@EnrollYear", user.EnrollYear),
new SqlParameter("@Tutor", user.Tutor),
new SqlParameter("@Major", user.Major),
new SqlParameter("@DptName", user.DptName),
new SqlParameter("@College", user.College),
new SqlParameter("@University", user.University),
new SqlParameter("@Content", user.Content),
new SqlParameter("@UserID", user.UserID)
};
return db.ExecuteNonQuery(sql, parameters);
}
}
|
|
|
|
|
These methods are not able to change. They have different functions in the CRUD operations. So, minimizing them won't help you in anything. Also you have not shared your BLL code, just the DAL code.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hi Afzaal, this codeproject textbox don't allow me to post too much codes in this Q&A, so I will post BLL code in the following. When I code these methods, I found I have to write same DAL, BLL again and again except of some different sql parameters. I think if I can input these parameters and the DAL and BLL code just write once. It will save a lot of time and energies and avoid a lot of errors.
public class UserBLL
{
private UserDAL userdal = new UserDAL();
public DataTable GetAllUser()
{
return userdal.SelectAllUser();
}
public bool AddUser(UserModel user)
{
if (userdal.InsertUser(user) > 0)
return true;
else
return false;
}
public bool DeleteUser(UserModel user)
{
if (userdal.DeleteUser(user) > 0)
return true;
else
return false;
}
public bool UpdateUser(UserModel user)
{
if (userdal.UpdateUser(user) > 0)
return true;
else
return false;
}
}
public class UserModel
{
public string UserID
{
get;
set;
}
public string Name
{
get;
set;
}
public string Sex
{
get;
set;
}
public string DptName
{
get;
set;
}
public string Phone
{
get;
set;
}
public string Major
{
get;
set;
}
public string University
{
get;
set;
}
public string Tutor
{
get;
set;
}
public string EnrollYear
{
get;
set;
}
public string College
{
get;
set;
}
public string Content
{
get;
set;
}
public string Pass
{
get;
set;
}
}
|
|
|
|
|
I don't think you should be making any further changes or fixes to your code, it is already in a compact shape.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you very much, Afzaal. Do you know some other more advanced architectures than the three layered one ? This must be old fashioned architecture I learn.
|
|
|
|
|