I'm trying to create a login code and I'm not able to figureout the code, I'm just trying to compare the username & the password value from access table.
Usernames and passwords are in same access table, Table(User)>Column1(Users) and Column2(Pass). Using OleDB to create connection.
I want to do something like this:
for (int i = comboBox1.FirstIndex; i > comboBox1.TotalItems.Count; i++)
{
if (comboBox1.SelectedIndex == i && (textBox2.Text == DS.Tables[0].Rows[i][0].ToString()))
{
//Run a set of commands
this.Close();
return;
}
}
Any better ideas please???

16 answers
Your question's not very clear but I'd guess that all possible usernames are listed in comboBox1 in the same order as the records in the datatable and that a user is expected to select his/her name from the combobox and then enter the password in textBox2.
You then need to test whether the password entered corresponds with that user's password in the datatable.
If that's the case, then the following code should do it:
answered one year ago by:
17279
412
Let me try this.... it had not worked still. Btw how can I get (fetch) the text value of the currently selected text in my comboBox1???? cdtext = comboBox1.SelectedItem.ToString();
17279
Yes, that's the way to do it.
Bcoz commetns section does not support code tags so I'm posting this as an answer to make it clear.
What I've tried to do is that the background remains disabled till the active form is closed. But this combination is not working.... I'm having Form1, it opens LoginForm, successful log in open Editable form.
There's no formclosing event added in Login Form.....
In present case the Form1 remains disabled even when Editables Form is closed....
answered one year ago by:
412
17279
You need to add EF.Show() in LoginForm_FormClosed. Apart from that, it should work.
Adding EF.Show(); LoginForm_FormClosed events breaks this code and Editables form does not opens. Okie leave it, I'm planning to drop this enabling thing as it's not so important.
Now another Important feature I had thought of is that, I can prompt a user about the documents which have to be released today in all the running Projects.
My xml is:
<cni>
<proj1>
<date></date>
</proj1>
<proj2>
<date></date>
</proj2>
<proj3>
<date></date>
</proj3>
</cni>
I've already populated all Proj tags in DropDownList & into DGV also
all I want is that I wish to check complete xml. Something like this:
Display the <Proj> tag. How to fetch this Proj in Complete xml?
answered one year ago by:
412
Do you mean something like this ** ?
** includes EDIT - see comments below
answered one year ago by:
17279
Gud Mrng from India
Hey vulpes, variable named projs have been used in this code, but have not be defined. Can we use the name of the table directly like this in the code? Kindly tell me what is this variable?
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + filename + ";Jet OLEDB:Database Password=SomeThinG");conn.Open();
var comm = new OleDbCommand("SELECT proj FROM projs", conn);
var adapter = new OleDbDataAdapter(comm);
DataSet DS = new DataSet();
adapter.Fill(DS, "proj");
comboBox1.DataSource = DS.Tables[0];
comboBox1.DisplayMember = "proj";
comboBox1.ValueMember = "proj";
conn.Close();
cdtext = DS.Tables[0].Rows[comboBox1.SelectedIndex][0].ToString();
My mdb file contains a table named projs and that table contains proj column, which is having names of all projects in it.
answered one year ago by:
412
17279
Sorry, projs is a List<string>. I've edited the code to include its declaration. It shouldn't interfere with the projs table in the database but I've changed the name to projects to avoid any confusion.
Earlier I was trying to create it separately and call it in form_Load but now I've added it in form_load itself. still its not behaving like a good boy
Edit:
PS:
My xml file has two different projects with documents having today's date in them. So I should see names of Two projects in the popup message.
I just found out that: Proper Popup (with project name) is displayed ONLY if the xml/DGV's last row's Date is Today.
Otherwise the Projects.count remains Zero, and so the Popup for projects.count == 0 is displayed two times bcoz two projects are having Today's date in them.
answered one year ago by:
412
17279
If the message never appears then, on the face of it, there can't be a row in the DGV whose Date column contains today's date. In that event, the code would never enter the block of the outer 'if' statement.
17279
I don't know what you're doing with this line: DataRow dr = dt.Rows['i']; but 'i' is a char literal which (in this scenario) is implicitly converted to an int with the same unicode value, namely 105. So, in other words, you'll always get the 106th row for every iteration of the for loop.
that DataRow dr = dt.Rows['i']; appeared logical to me..... U can find this in http://www.debugging.com/bug/23870 5th post... u've suggested this in a solution to sort the DGV where I was using one column as "Date" and another column as "Time". but I have to later change the appearance of my xml file and have to dropout the "Time" from it. It appeared logical that we are moving thru Row[0] to Row[dt.Rows.Count-1].... it's something different?
Okie let's say after finishing of that for loop if I again write something like DataRow DR = dt.Rows[0]; (Zero) then also it dosen't helps.
All Today's dates.....which exists before the last project in the xml are ignored. and the projects.Count remains zero. Whenever I select (comboBox1) that project which is having today's date... the message from projects.Count == 0 is displayed. But the row is highlighted to show that it's having today's date.
Confusing.... or maybe I'm not able to explain.
answered one year ago by:
412
17279
In the post you refer to the line was DataRow dr = dt.Rows[i] where i was the integer loop control variable which I'd have thought is what you want here. But, apart from that, the code looks OK to me and so I think the answer must lie with the XML file. Can you post the contents (or an extract) of this file so I can try it myself.
Here's the xml file.....
answered one year ago by:
412
I think I'm now beginning to see the wood from the trees!
In sorting out today's deliverables, you don't want to be looking at the DGV at all (which only displays the rows of a single table). You simply need to be iterating through the tables themselves and determining those which have rows whose Rel_Date column shows today's date.
So, the revised code will now be:
answered one year ago by:
17279
BINGO!!!!! Man u did it again.....
Figuring out these logics is a tough thing for me.... As u now know that the comboBox1 in my form fetches the list of projects, that name of the project in comboBox1 is same as that in the xml file. So when the user selects a particular project, that name is sent as DataTable dt = ds.Tables[cdtext]; and rows of THAT project only is populated & displayed in my DGV. Now just see this code below....
I'm simply trying to export my DGV which is visible to the user, using Office 11.0 Object Library... using Excel = Microsoft.Office.Interop.Excel;
I'm planning to do the formatting of my Excel document. Needs help with formatting, like:
Plz try and see....
answered one year ago by:
412
I'm not too hot on programatically formatting stuff in Excel but I have managed to figure out how to deal with those three requirements:
There's a table of Excel colors and their indices here.
answered one year ago by:
17279
The line to give color to font is corrected as this:
((Excel.Range)excelSheet.Cells[1, column.Index + 1]).Font.ColorIndex = 10; otherwise it is not working, The font color remains Black only.
Now....
Just a doubt.... can we change the name of Sheet1 to something else and remove remaining Sheet2 & Sheet3 also????
answered one year ago by:
412
To do that change the first two lines to the following:
EDIT - see comments below
The Office object model was originally designed for VBA/COM programmers and has always been pretty horrible for C# folks to use with its liberal use of 'variant' return types, indexed properties and optional parameters. Many C# developers just gave up and used VB.Net instead which does support all this stuff.
However, muster is right - MSDN does have the best articles on the subject - and I'd check out this one in particular and also some of the others listed in the TreeView to the left of that page.
Incidentally, if you upgrade to VS 2010, you'll find that Office interop has suddenly become much nicer now that C# supports the 'dynamic' keyword and optional/named parameters. It also supports indexed properties but only for Office/COM interop.
It's even possible now for your application to extract only those bits of the Primary Interop Assemblies (PIAs) that it needs which improves performance and makes deployment much easier :)
answered one year ago by:
17279
Thx..... That's wonderful piece of help.
I might have exported a nice looking xls file with ur help... But I'm not satisfied with the amount of learning in Office.Interop thing... sounds too tricky and confusing. Can u please help me out with a good tutorial for a newbie(in Office.Interop)? Would be wonderful....
I want to have a better look into this thing otherwise it feels as if I'm trying-out with some alien language.
In the meanwhile I'm also trying to search something. I felt that it would be great if I can do something easy so that my DGV can display the xls file without much doing finguring in my DGV. So I need some help/tutorial for Office.Interop......
answered one year ago by:
412
1556
hey, you can still learn more about Office.Interop by going to the msdn website and it will be your sufficient reference afaik.
17279
I've tried twice now to add another answer but both attempts have disappeared into thin air even though the answer count was incremented! I've therefore edited my last answer instead.