|
|
I can't get access to the reader in
private void btnLogin_Click(object sender, System.EventArgs e)
here is the whole program. I know it is somethinge very basic. Please point it out to me.
Thanks Brian
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
<br />
}<br />
<br />
#region Web Form Designer generated code<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
}<br />
<br />
private void InitializeComponent()<br />
{ <br />
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();<br />
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();<br />
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();<br />
<br />
this.dbLoginInfo1 = new dbLoginInfo();<br />
((System.ComponentModel.ISupportInitialize)(this.dbLoginInfo1)).BeginInit();<br />
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);<br />
this.lblMessageTextBox1.TextChanged += new System.EventHandler(this.lblMessageTextBox1_TextChanged);<br />
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;<br />
this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] <br />
{<br />
new System.Data.Common.DataTableMapping("Table", "tblEmployee", new System.Data.Common.DataColumnMapping[] <br />
{<br />
new System.Data.Common.DataColumnMapping("EmployeeID", "EmployeeID"),<br />
new System.Data.Common.DataColumnMapping("FName", "FName"),<br />
new System.Data.Common.DataColumnMapping("LName", "LName"),<br />
new System.Data.Common.DataColumnMapping("Password", "Password"),<br />
new System.Data.Common.DataColumnMapping("Username", "Username")<br />
})});<br />
this.oleDbSelectCommand1.CommandText = "SELECT EmployeeID, FName, LName, [Password], Username FROM tblEmployee";<br />
this.oleDbSelectCommand1.Connection = this.oleDbConnection1;<br />
this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Data Source=""D:\MGDevelopment\SIMDAC Viewer\DB\simdac_be.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";<br />
this.dbLoginInfo1.DataSetName = "dbLoginInfo";<br />
this.dbLoginInfo1.Locale = new System.Globalization.CultureInfo("en-US");<br />
this.Load += new System.EventHandler(this.Page_Load);<br />
((System.ComponentModel.ISupportInitialize)(this.dbLoginInfo1)).EndInit();<br />
try <br />
{<br />
this.oleDbConnection1.Open();<br />
}<br />
catch (OleDbException ex) <br />
{<br />
}<br />
OleDbDataReader OleDbReader = this.oleDbSelectCommand1.ExecuteReader(CommandBehavior.CloseConnection);<br />
while(OleDbReader.Read())<br />
{<br />
string sUserName = OleDbReader["UserName"].ToString();<br />
string sPassword = OleDbReader["Password"].ToString();<br />
<br />
}<br />
<br />
}
|
|
|
|
|
|
Sorry for onitting this.
private void btnLogin_Click(object sender, System.EventArgs e)<br />
{<br />
if (Page.IsValid) <br />
<br />
{<br />
while(OleDbReader.Read())<br />
{<br />
if(txtUserName.Text==OleDbReader["UserName"].ToString()&&<br />
(txtPassword.Text==OleDbReader["Password"].ToString()))<br />
{<br />
Response.Redirect("SelArptFrmSet.htm");<br />
}<br />
else<br />
{<br />
lblMessageTextBox1.Text = "Invalid Login!";<br />
lblMessageTextBox1.Visible=true;<br />
}<br />
}<br />
}<br />
}
|
|
|
|
|
Thank you very much!
I removed the code from the Initial component area and placed it in the btn.
Works fine.
Brian
|
|
|
|
|
Your InitializeComponent() method contains some code to read information from the database. This does not look like code that Visual Studio added to this method. Please note that Visual Studio put at the top of the method some very useful comments:
You should not have code reading anything from the database in this method.
When your button click event is fired the contents of the data reader are exhausted becuase of the code in the InitializeComponent() method so there is no more data to get, therefor the method does not function as expected.
It is good practice to open a Data Reader, get the data and close it all in one sequence. In this case that sequence should be in the button click event.
Does this help?
My: Blog | Photos | Next SQL Presentation
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Hello,
Does anyone know how to get ThreeState checkbox behavior in a TreeView? This seems like it would be a fairly common need. If all subnodes are checked, I want a regulary checked state. If only some of the child nodes are checked, I want a "partial" checked state.
Any ideas?
Thanks!
-Ian
|
|
|
|
|
|
Thanks for you help! I appreciate it!
-Ian
|
|
|
|
|
I'm trying to send commands from my C# project to the command line. The cmd is opening but the arguments are not being passed. Here is my code:
System.Diagnostics.ProcessStartInfo psi = null;
System.Diagnostics.Process proc = null;
psi = new System.Diagnostics.ProcessStartInfo("cmd");
proc = new System.Diagnostics.Process();
proc.StartInfo = psi;
System.Diagnostics.Process.Start(psi);
psi.Arguments = @"ping dev12";
Application.DoEvents();
System.Diagnostics.Process.Start(psi);
proc.WaitForExit();
Thanks.
|
|
|
|
|
The argument ARE being passed. You're just not supplying the correct arguments to CMD. The command line your passing in is this:
cmd ping dev12
Try typing that in a Start/Run box and watch what happens.
What you should be passing in is:
cmd /c ping dev12
The "/C" tells CMD to execute the following string and a command, then terminate when that command is done.
"/K" will tell CMD to remain open after the command it execute returns.
All you have to do to find this out is type "CMD /?" at a command prompt.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
HI,
In my project,i am having requirement that i want to use total 6-7 different variables in one class from another form.Now how to access all that variables
in my class.
i don't want to write 6-7 properties,i know that way but anybody know any simple and efficient way to do this?
|
|
|
|
|
write a public method that returns an array with the parmaters?
there are no facts, only interpretations
|
|
|
|
|
If both the classes (or form) are in the same assembly, you can use the "internal" access-modifier for those variables to access them directly. This way, you won't have to declare them public.
|
|
|
|
|
Both other answers are correct, but here's another:
class Person
{
public string Name;
public int Age;
}
Person p = new Person();
p.Name = "Luis";
p.Age = 23; Good luck!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Does anyone know how to get a reference to the Label Edit TextBox control while it is being displayed?
Gary Kirkham
Forever Forgiven and Alive in the Spirit
He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot
Me blog, You read
|
|
|
|
|
Gary Kirkham wrote:
get a reference to the Label Edit TextBox control while it is being displayed
What? Are you talking about dropping a Label control on the form at design time?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am talking about the text box that is displayed when you click on an item in the list (LabelEdit = true). I want a reference to that textbox when it is displayed.
Gary Kirkham
Forever Forgiven and Alive in the Spirit
He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot
Me blog, You read
|
|
|
|
|
Hmmm...There's no way to get it directly. The ListView creates that edit box on-the-fly and it only exists for as long as your typing in it. About the only way to do this would be to use the GetWindow API functions to enumerate the windows of the application and look for a specific window class. I can see a couple of possibl problems though. First, the window class used by the edit box can be used by TextBox's also. I think you'll also have to find a way to get the parent window handle from the windows that you find and compare it to the handle of the ListView. I don't know if they'll actually match though, or if you can even get that parameter from the edit box window.
Hmmm...A very interesting research project...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I don't know how to write to binary file only one bit and not one byte.
Please help me!
FileStream fs new FileStream("1.dat", FileMode.CreateNew);
BinaryWriter w = new BinaryWriter(fs);
w.Write(true); //write one byte
w.Write(55); //write 4 bytes
fs.Close();
Thanks
|
|
|
|
|
The smallest unit you can write to a file is 1 byte. Even though you're writing a single bit to a file, any file operation you try and use will only write a single byte to store your bit in.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
the overloaded BinaryWriter.Write() method does not support anything smaller than a byte, which is the smallest natural unit. Note that the bool type is not a bit long.
You can try using a BitArray , but i'm not sure this will help, and it's not very efficient.
there are no facts, only interpretations
|
|
|
|
|
I'm creating a console based app and want to set it so when minimized, it'll go to the notify icon area of the taskbar so that it can run in the background and not take up valuable space on the taskbar.
I have been trying for about a week to figure this out.. to no avail.
I am still learning C#.. but love what I have accomplished. Anyone here willing to show me how to do this?
Also, if possible, set the icon and name of the Console that comes up insead of having the standard "Windows/.../.../cmd.exe" and icon -- I want to be able to set the name and icon of the Console (again, if possible). I have the icon to use already - for the minimized notifyicon image and for the console icon - but I do not know how to set it. I have set the "Windows Icon" for the program already, but once the program is ran.. you don't see the icon in the app.
|
|
|
|
|
You should try the NotifyIcon class. E.g.
NotifyIcon ni = new NotifyIcon();
ni.Icon = new System.Drawing.Icon(your icon path)
ni.Visible = true;
Note that in a console application, you need to reference the drawing dll and the windows dll yourself.
mdavis93 wrote:
and not take up valuable space on the taskbar.
for this i think you need your work to be done in a separate, windowless thread.
there are no facts, only interpretations
|
|
|
|
|
When the application is minimized, how can I remove it from the taskbar.. so the icon in the NotifyIcon is the only thing showing that the program is running... and then how do I open the console back up? Also.. What would be the correct syntax to close the Icon?
Here's the start of my "Main" section:
public static void Main (string[] args)
{
NotifyIcon ni = new NotifyIcon();
ni.Icon = new System.Drawing.Icon("C:/Icon.ico");
ni.Visible = true;
if ( Disconnecting )
{
ni.Dispose();
ni.Visible = false;
writer.Close();
stream.Close();
irc.Close();
stream.Close();
}
Thanks for the help.. it's greatly valued!
|
|
|
|