|
If someone wants to know the following[^] will help ...
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Hi Im a newbie to c#
I want to connect to access 2007 db which has usernames and passwords stored in a table called USERS
If there is a username and password in the db that matches what the user has entered into the textboxes in the form then the form1 can be displayed otherwise an error message is displayed.
Heres my code so far
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Xml.Serialization ;
using ADODB;
public partial class login : Form
{
private ADODB.Connection cn = new ADODB.Connection();
private ADODB.Recordset rs = new ADODB.Recordset();
private string cnStr;
private string query;
public login()
{
InitializeComponent();
}
private void login_Load(object sender, EventArgs e)
{
//Connection string.
cnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\resources\pw.accdb;Persist Security Info=False;";
//query
query = "Select * From USERS";
//Connection via Connection open Property.
cn.Open(cnStr, null, null, 0);
cn.Close();
//Connection via ConnectionString Property.
cn.ConnectionString = cnStr;
cn.Open(null, null, null, 0);
cn.Close();
}
private void btnLOGIN_Click(object sender, EventArgs e)
{
//Open Recordset via Connection object. retrieves the recordset from the db
cn.Open(cnStr, null, null, 0);
rs.Open(query, cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
rs.Close();
cn.Close();
string command = "SELECT UN, PW FROM USERS";
//NOW CONFUSED HERE - DONT KNOW WHAT TO DO NEXT
}
}
Basically all I need in c# code is the following pseudo code;
Button submit_Click()
select un, password from users
if txtun.text = UN and txtpw.text = PW
me.hide
form1.show
else
msg(Error - Your input details are incorrect);
end if
Please help as I've been over it several times.
Thanks
JB
|
|
|
|
|
hey jb,
first of all please use pre tags when you posting so much code, no on wants to read non-indented code...
try using this query
SELECT COUNT(userID)
WHERE userName = 'yourUserNameTextBoxText' AND password = 'yourPasswordTextBoxText'
then in the program just check that the return value of that query == 1; if not there was no match therefore either the username or password was incorrect
good luck
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
In a Page (there is no async=true tag); i call a procedure asynchrously. Sometimes it calls the callback; sometimes not. Why do i face this reason?
private void AsynchronProcedure()
....
try
{
dbSqlConnection.Open();
IAsyncResult asyncResult = dbSqlCommand.BeginExecuteNonQuery(MyCallBack, dbSqlCommand);
}
catch (Exception ex)
{
}
finally
{
dbSqlConnection.Close();
}
}
private void MyCallBack(IAsyncResult asyncResult)
{
SqlCommand dbSqlcommand = (SqlCommand)asyncResult.AsyncState;
try
{
if (asyncResult.IsCompleted)
{
dbSqlcommand.EndExecuteNonQuery(asyncResult);
}
}
catch (Exception ex)
{
}
}
|
|
|
|
|
greekius wrote: In a Page (there is no async=true tag); i call a procedure asynchrously.
Two different things. The former for for page handling. The latter is you. Neither has an effect on each other.
greekius wrote: Sometimes it calls the callback; sometimes not. Why do i face this reason?
Your code is wrong. You should close the connection after the callback returns, not before it (as you are doing now, not really, it depends, but the fact is the connection can and likely will be closed before the async call can complete).
|
|
|
|
|
Hello everyone,
For the following code, the compile error is,
error CS0051: Inconsistent accessibility: parameter type 'TestEnum1.Goo.Level' is less accessible than method 'TestEnum1.Foo.Test(TestEnum1.Goo.Level)'
My fix is to make class Goo public, is it correct fix? Why there is such compile error?
class Goo
{
public enum Level
{
Error = 0,
Warning = 1
}
}
public class Foo
{
static public void Test(TestEnum1.Goo.Level l)
{
return;
}
}
thanks in advance,
George
|
|
|
|
|
Gosh George, you post here so much, and you can't understand this error message ? The class is public, the method is public, but Goo is not public. How can someone call Foo.Test, if they have access to this method, but not access to the type of class they need to pass in ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian,
I have did some search in MSDN, about access modifier for class level, other than for method level. But I can not find any information. Any recommended links? I feel as you said, the root cause is my knowledge about access modifier for class level.
regards,
George
|
|
|
|
|
Well, isn't it clear ? You are exposing a method which takes an object. It's possible for someone to have access to the method, but not to the object that needs to be created. Therefore, your intention appears to be to expose a method, but unless you make that other class public, your user won't be able to call it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian!
I understand your points. My point is just to "learn more". Do you have any reference documents or tutorials about the topic of access modifier of class level? I think I missed this part of knowledge.
regards,
George
|
|
|
|
|
As is often the case, I have no idea what you're asking, but I think you're over complicating things. The access modifier is private, protected or public. I can't imagine too much has been written beyond explaining the difference between the three.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Sorry, Christian!
My English is not good. I mean what are the restrictions of public/protected/private classes? Are there any documents for them?
regards,
George
|
|
|
|
|
OK - got it. The only restriction is, who can create them. The use of a private class is to define a class within another, that cannot be created outside that class. For example, I may use a class to define a group of values within the class, but not want a user to ever create an instance of it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian,
I almost get your ideas. Are there any MSDN or other documents? It is strange I can not find any related documents about public/protected/private classes.
regards,
George
|
|
|
|
|
The concept is so simple that it doesn't warrant a lot of documentation. There's really not much more to say. Your best bet is to google the error message in quotes, to get the MSDN explanation
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian,
Can I understand the root cause of my original issue in this way? The class is not public (default private?) and the type inside the class is public -- more visibility then outer type?
regards,
George
|
|
|
|
|
Correct
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian,
I think for Enum, it is treated as a type, so a non-public class can not have a public nested Enum type.
And for methods, it is not under this rule, e.g. a non-public class could have a public method. Correct?
regards,
George
|
|
|
|
|
As Christian said, you are really complicating things. It's okay to learn and ask questions about specific problems. But for some little things like this there's no need to buy a book or read dozens of pages. The compiler warns you about a very common problem which you could have solved by adjusting the access modifiers to suit your needs.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
Hi, i got a Link list which stores an Entity object( string name, string type, int level)
how do i sort the list in order of name(alphabetically) and level(ascending or descnding)
|
|
|
|
|
By writing a sort function and calling the Sort method with that as the sort function. There's tons of good examples on MSDN and elsewhere.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i cant find a website that shows the C# sort function on msdn
|
|
|
|
|
A LinkedList[^] does not have a sort functionality. Are you sure you don't use a normal ArrayList[^], or better, a List<T>[^].
If yes, then this link[^] is for you.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
this is the linklist class i created
class LinkedList
{
private Node head, tail;
private int size;
public LinkedList()
{
head = null;
size = 0;
}
public Node Tail
{
get { return tail; }
}
public Node Head
{
get { return head; }
}
public int Size
{
get { return size; }
}
public void AddFront(object data)
{
Node newNode = new Node(data, head);
if (head == null)
tail = newNode;
head = newNode;
size++;
}
public void AddRear(object data)
{
Node newNode = new Node(data, null);
if (head == null)
{
head = newNode;
tail = newNode;
size++;
}
else
{
tail.Link = newNode;
tail = newNode;
size++;
}
}
public bool DeleteFront()
{
if (head == null)
return false;
else
{
head = head.Link;
size--;
return true;
}
}
And this is my Node class
using System;
namespace GameCharacterTrackingSystem
{
public class Node
{
object data;
Node link;
public Node(object d, Node l)
{
data = d;
link = l;
}
public object Data
{
get
{
return data;
}
set
{
data = value;
}
}
public Node Link
{
get
{
return link;
}
set
{
link = value;
}
}
}
}
This is my Entity class which will create the object to be store in my linklist
using System;
using System.Collections.Generic;
using System.Text;
namespace GameCharacterTrackingSystem
{
class Entity
{
private string type;
private string name;
private int level;
public Entity()
{
type = null;
name = null;
level = 0;
}
public Entity(string type, string name, int level)
{
this.type = type;
this.name = name;
this.level = level;
}
public string Type
{
get { return type; }
set { type = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public int Level
{
get { return level; }
set { level = value; }
}
public override string ToString()
{
return "Type : " + type + ", Name : " + name + ", Level : " + level;
}
}
}
Inside LinkList.cs i want to add another method to sort the stored Entity by level, name and type.. how should the method be write?
|
|
|
|