|
hi all i am creating a login page and my problem was,
sp returns value for Num_of_User = 1 but the returnParam will always got a returnParamValue = 0..
what is wrong with this code...
this my code...
CREATE TABLE NorthWindUsers
(UserID INT IDENTITY(1,1) NOT NULL,
UserName VARCHAR(50) NOT NULL,
Password VARCHAR(50) NOT NULL)
INSERT INTO NorthWindUsers
(UserName, Password)
VALUES ('sachin', 'tendulkar')
alter PROCEDURE sp_ValidateUser
(
@UserName VARCHAR(50) = Null,
@Password VARCHAR(50) = Null,
@Num_of_User INT = 0
)
AS
SET @Num_of_User = (SELECT COUNT(*) AS Num_of_User
FROM NorthWindUsers
WHERE UserName = @UserName AND Password = @Password)
Return @Num_of_User
private void btnSubmit_Click(object sender, System.EventArgs e)
{
int maxLoginAttempts = (int)Session["MaxLoginAttempts"];
if (Session["LoginCount"].Equals(maxLoginAttempts))
{
Response.Redirect("WebForm1.aspx?reason=maxloginattempts");
}
if(Page.IsValid)
{
if(DBConnection(txtusername.Text.Trim(),txtPassword.Text.Trim()))
{
FormsAuthentication.RedirectFromLoginPage(txtusername.Text, false);
}
else
{
lblMessage.Text = "Invalid Login Please Try again....";
}
}
}
private bool DBConnection(string txtUser,string txtPass)
{
//int a;
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
SqlCommand myCommand = new SqlCommand("sp_ValidateUser", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter returnParam;
objParam1 = myCommand.Parameters.Add("@UserName", SqlDbType.VarChar);
objParam2 = myCommand.Parameters.Add("@Password",SqlDbType.VarChar);
returnParam = myCommand.Parameters.Add ("@Num_of_User",SqlDbType.Int);
objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
returnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = "txtuser";
objParam2.Value = "txtPass";
//a = Convert.ToInt32(myCommand.Parameters["@num_of_User"].Value);
try
{
if(myConnection.State.Equals(ConnectionState.Closed))
{
myConnection.Open();
returnParam = myCommand.ExecuteNonQuery();
//Int32 rowCount = (Int32)catDA.InsertCommand.Parameters["@RowCount"].Value;
}
if((int)returnParam.Value < 1 )
{
int loginCount = (int)Session["LoginCount"];
loginCount += 1;
Session["LoginCount"] = loginCount;
lblMessage.Text = "Invalid Login";
return false;
}
else
{
myConnection.Close();
return true;
}
}
catch (Exception ex)
{
lblMessage2.Text = ex + "Error connecting to the database";
return false;
}
}
|
|
|
|
|
There are too many problems with this.
wrote: @Num_of_User INT = 0
You have a parameter clash. You've defined this as a return value, yet here you are specifying it as an input parameter with a default value of zero.
wrote: objParam1.Value = "txtuser";
objParam2.Value = "txtPass";
This passes a string literal to the parameter, so the stored procedure will never get the value passed in to the method, so it will never find anything because it does not match what you inserted into the database.
wrote: if(myConnection.State.Equals(ConnectionState.Closed))
{
myConnection.Open();
This is redundant. The connection will always be closed as it is newly created.
Here is a simpler solution:
For something this simple, I'd use ExecuteScalar and get the value from the SELECT directly
SQL:
alter PROCEDURE ValidateUser
(
@UserName VARCHAR(50) = Null,
@Password VARCHAR(50) = Null
)
AS
SELECT COUNT(*)
FROM NorthWindUsers
WHERE UserName = @UserName AND Password = @Password
GO
The sp prefix was removed because in SQL Server this may clash with system stored procedures. If SQL Server sees a stored procedure call starting with sp it goes to the master database first.
C#
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
SqlCommand myCommand = new SqlCommand("ValidateUser", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1 = myCommand.Parameters.Add("@UserName", SqlDbType.VarChar);
SqlParameter objParam2 = myCommand.Parameters.Add("@Password",SqlDbType.VarChar);
objParam1.Value = txtuser;
objParam2.Value = txtPass;
myConnection.Open();
int returnParam = (int)myCommand.ExecuteScalar();
myConnection.Close();
....
The direction was dropped, as all parameters are Input by default.
|
|
|
|
|
i wanto encrypt a film and then write a program that only with this program my user can see that film...
what's the best solution for this ?
|
|
|
|
|
That depends upon the level of security you want. There are several public domain encryption functions out there which are very good.
But from a practical viewpoint, if you aren't protecting something extremely valuable, just do something unexpected with the contents of the file. A very weak encryption. It still won't be worth anyone's time to try to figure it out.
For instance, for every group of 5 bytes in the file, reverse the order of those 5 bytes.
Mark
|
|
|
|
|
Hi,
I'm writing a LoadGenerator application, in which for a specific period of time
certain no.of Threads are created and executes simultaneously..
That i call as RampUp threads.
After sleeping for a sustain period (10secs) of time.. I want to RampDown threads, that is i want to kill the threads one by one..
I have defined an ArrayList object alThreads to maintain the Threads list..
RampUp() method
public void RampUp()
{
for(int i=0; i<10; i++)
{
Thread thread = new Thread(ExecuteSingleThread);
thread.Start();
if(alThread.Contains(thread) == false)
{
alThreads.Add(thread);
}
Thread.Sleep(5000);
}
}
The below code kills the thread every five second..
RampDown() method
public void RampDown()
{
for(int i=0;i<alThread.Count;i++)
{
Thread thread = (Thread)alThreads[i];
if(thread.IsAlive)
thread.Abort();
Thread.Sleep(5000);
}
}
Now the problem is after killing the first thread, all the remaining threads
doesn't executes the code inside it..
Please help me..
regards,
nas
|
|
|
|
|
Try looping through the threads from count-1 to 0...
Note that aborting a thread throws an exception which you need to catch.
<br />
for(int i=alThreads.length-1;i >= 0; i--)<br />
{<br />
Thread thread = (Thread)alThreads[i];<br />
if(thread.IsAlive)<br />
thread.Abort();<br />
Thread.Sleep(5000);<br />
}<br />
|
|
|
|
|
Thanx
|
|
|
|
|
Hi..
in my application i have implemented runtime compilatio of C# code..
its working fine..
Knowingly i made 7 to 8 mistakes in C# code and passed it to the CodeDomProvider's object..
after compilation it throws the errors.. but instead of displaying all the 7 errors.. it display only 4 errors.
i tried to set the capacity of the Errors list.. that is
objCompilerResults.Errors.Capacity = 100
but still gets the same.
Plz help me how to get all the errors.
regards,
nas
|
|
|
|
|
hi,
i have created a editor in RichtextBox and i implemented a feature of compiling
When ever i compile i am getting only first 4 errors at a time
if I correct those errors it will show further.
so only it is displaying only 4 errors.
i.e . it is Compiler.result capacity is only four
how to increase the count/capacity
With Regards
Prasad
-- modified at 6:42 Thursday 22nd February, 2007
|
|
|
|
|
What is the procedure for adding crystal report Version 10 Licence, Product key or registration key in order to aid its deployment
|
|
|
|
|
I want to fill a combo box with values from a field in a table. Hod do I?
|
|
|
|
|
Select the values from the DB, set the datatable to be the datasource and set the displaymember to be the name of the column.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello Bonjo,
Use
comboBox1.Items.AddRange();
or
for each item in itemscollection
comboBox1.Items.Add(item);
Regards ,
nishu
|
|
|
|
|
when i write this:
serialport1.write(); so it sends 4 byte and i can get just lsb byte.cause my receiver can read just char(getc();)
i want to send with visual c# (0-255) numbers?how can i do it?
|
|
|
|
|
byte[] b = new byte[1] { 10 };
serialport1.Write(b, 0, b.Length);
|
|
|
|
|
Details
I used C#.Net 2005 and SQL 2000 as back end.
I wrote stored procedure to retrieve record (for the report) from the server.
I used Crystal Report (C#.Net 2005) to prepare the report through crystalReportViewer.
I also wrote codes in “Code View” of a Form to load the report.
The report runs perfectly in isolation.
The report also runs very well from the Application prior to deployment.
Problem
The report however, could not be loaded after deployment while other parts of the app run effectively.
It generates an error “Load Report Failed” when attempt to load the report is made.
Although, this is my first deployment with crystal report.
Assumption
I suspect the absence of required file(s) that should be added during deployment in order to aid the loading of a crystal report file, since the report runs in “IDE” before deployment or do you think otherwise?
There is also an insinuation from a friend of the need to add a product key or license key or registration number for the crystal report to work fine, which I do not know the procedure or know-how.
• Please assist in solving my problem so that I can deploy appropriately.
Thanks in advance.
Banjo Ayorinde
This is the code for the report:
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.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
namespace UI
{
public partial class rptFrmEmpEmpNo : Form
{
public rptFrmEmpEmpNo()
{
InitializeComponent();
}
private static rptFrmEmpEmpNo instance = null;
public static rptFrmEmpEmpNo getInstance()
{
if (instance == null)
instance = new rptFrmEmpEmpNo();
return instance;
}
// stirng to hold connection to the server
public string Link_DB_ConnectionString()
{
return "Server=.;initial catalog=LabourData;User ID=sa;Password=sa";
}
private long EmployeeNo;
// codes to fill Employee combo box with employee names
private void FillEmployeeCombo()
{
string EmpId,EmpNo,EmpLastName,EmpFirstName;
SqlConnection EmpNoConnect = new SqlConnection(Link_DB_ConnectionString());
try
{
EmpNoConnect.Open();
//Create SQL statement
string EmpNoString = "SELECT EmployeeId, EmployeeNo, LastName, FirstName FROM tbl_Employee ORDER BY LastName ASC";
SqlCommand EmpNoCommand = EmpNoConnect.CreateCommand();
EmpNoCommand.CommandText = EmpNoString;
// A SqlDataAdapter uses the SqlCommand object to fill a DataSet.
SqlDataAdapter EmpNoDataAdapter = new SqlDataAdapter(EmpNoCommand);
// Create a new Dataset and fill its first DataTable.
DataSet EmpNoDataset = new DataSet();
EmpNoDataAdapter.Fill(EmpNoDataset, "tbl_Employee");
// mySqlDataAdapter = new SqlDataAdapter(mySqlCommand);
SqlDataReader EmpNoDataReader = EmpNoCommand.ExecuteReader();
while (EmpNoDataReader.Read())
{
EmpId = EmpNoDataReader.GetValue(0).ToString();
EmpNo = EmpNoDataReader.GetValue(1).ToString();
EmpLastName = EmpNoDataReader.GetValue(2).ToString();
EmpFirstName = EmpNoDataReader.GetValue(3).ToString();
this.cmbEmployeeNo.Items.Add(EmpNo + " " + EmpLastName + " " + EmpFirstName);
this.LstEmpId.Items.Add(EmpNo);
}
EmpNoDataReader.Close();
EmpNoConnect.Close();
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
}
private void cmbEmployeeNo_SelectedIndexChanged(object sender, EventArgs e)
{
LstEmpId.SelectedIndex = cmbEmployeeNo.SelectedIndex;
EmployeeNo = Convert.ToInt64(LstEmpId.SelectedItem.ToString());
}
private void ClearEmployeeCombo()
{
cmbEmployeeNo.Items.Clear();
LstEmpId.Items.Clear();
}
private void rptFrmEmpEmpNo_Load(object sender, EventArgs e)
{
ClearEmployeeCombo();
FillEmployeeCombo();
}
private void bttnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private string ServerName = ".";
private string UserID = "sa";
private string Password = "sa";
private string DatabaseName = "LabourData";
//codes to load the report through the report viewer
private void bttnDisplay_Click(object sender, EventArgs e)
{
// In this event the Customer Orders Report is loaded
// and displayed in the crystal reports viewer.
// This report calls for a parameter which is pulled
// from the customer name combo box (cbCustomers).
// Objects used to set the parameters in the report
CrystalDecisions.Shared.ParameterValues pvCollection = new CrystalDecisions.Shared.ParameterValues();
CrystalDecisions.Shared.ParameterDiscreteValue pdvEmpEmpNo = new CrystalDecisions.Shared.ParameterDiscreteValue();
// Objects used to set the proper database connection information
CrystalDecisions.Shared.TableLogOnInfo tliCurrent;
// Create a report document instance to hold the report
ReportDocument rptEmpEmpNo = new ReportDocument();
try
{
// Load the report
rptEmpEmpNo.Load(@"..\..\YCrystalReportEmpEmpNo.rpt");
// Set the connection information for all the tables used in the report
// Leave UserID and Password blank for trusted connection
foreach (CrystalDecisions.CrystalReports.Engine.Table tbCurrent in rptEmpEmpNo.Database.Tables)
{
tliCurrent = tbCurrent.LogOnInfo;
tliCurrent.ConnectionInfo.ServerName = ServerName;
tliCurrent.ConnectionInfo.UserID = UserID;
tliCurrent.ConnectionInfo.Password = Password;
tliCurrent.ConnectionInfo.DatabaseName = DatabaseName;
tbCurrent.ApplyLogOnInfo(tliCurrent);
}
// Set the discreet value to the reg number.
pdvEmpEmpNo.Value = LstEmpId.Text;
// Add it to the parameter collection.
pvCollection.Add(pdvEmpEmpNo);
// Apply the current parameter values.
rptEmpEmpNo.DataDefinition.ParameterFields["@EmployeeNo"].ApplyCurrentValues(pvCollection);
// Hide group tree for this report
crvEmpEmpNo.DisplayGroupTree = false;
// Set the report source for the crystal reports viewer to the
// report instance.
crvEmpEmpNo.ReportSource = rptEmpEmpNo;
// Zoom viewer to fit to the whole page so the user can see the report
crvEmpEmpNo.Zoom(1);
}
catch(LoadSaveReportException Exp)
{
MessageBox.Show("Incorrect path for loading report.", "Load Report Error");
}
catch( Exception Exp)
{
MessageBox.Show(Exp.Message, "General Error");
}
}
}
}
Banjo Ayorinde
|
|
|
|
|
Hi
I have problem in loading form back and forth. In form1 if i click next button I am showing form2 and hiding the form one. But when i click the cancel button in the form2 it will ask do you wan to exit with ok and cancel button if i click ok it is exiting the current application. if i click cancel the application is still running but i could able to see any form. any one help me please.
form1 code:
```````````
btnnext_click(object sender,eventargs e)
{
form2 objform2=new form2(this);
objform2.ShowDialog();
}
btncancel_click(object sender,eventargs e)
{
if(messagebox.show("Do you want to exit","Exiting", messageboxokcancel,messageboxquestion).equals(dialogresult.ok)
system.window.form.exit();
}
form2 code:
```````````
private Form frmForm1;
public form2(Form objForm)
{
frmForm1=objForm;
}
btnnext_click(object sender,eventargs e)
{
form3 objform3=new form3(this);
objform2.ShowDialog();
}
btncancel_click(object sender,eventargs e)
{
if(messagebox.show("Do you want to exit","Exiting", messageboxokcancel,messageboxquestion).equals(dialogresult.ok)
system.window.form.exit();
}
btnback_click(object sender, eventargs e)
{
frmForm1.visible=true;
}
kesavan
|
|
|
|
|
Hi
I have problem in loading form back and forth. In form1 if i click next button I am showing form2 and hiding the form one. But when i click the cancel button in the form2 it will ask do you wan to exit with ok and cancel button if i click ok it is exiting the current application. if i click cancel the application is still running but i could able to see any form. any one help me please.
form1 code:
```````````
btnnext_click(object sender,eventargs e)
{
form2 objform2=new form2(this);
objform2.ShowDialog();
}
btncancel_click(object sender,eventargs e)
{
if(messagebox.show("Do you want to exit","Exiting", messageboxokcancel,messageboxquestion).equals(dialogresult.ok)
system.window.form.exit();
}
form2 code:
```````````
private Form frmForm1;
public form2(Form objForm)
{
frmForm1=objForm;
}
btnnext_click(object sender,eventargs e)
{
form3 objform3=new form3(this);
objform2.ShowDialog();
}
btncancel_click(object sender,eventargs e)
{
if(messagebox.show("Do you want to exit","Exiting", messageboxokcancel,messageboxquestion).equals(dialogresult.ok)
system.window.form.exit();
}
btnback_click(object sender, eventargs e)
{
frmForm1.visible=true;
}
form2_load()
{
------ some code
------ some code
frmForm1.visible=false;
}
sorry i missed the load event. Any one help me please
kesavan
|
|
|
|
|
i'm not quite sure what exactly is you problem, is it not being to close the application or not being able to show the forms.
but i did have a look at your code. the code below is in c# (which is similar to your code) and worked fine for me.
form1:
------
<br />
private void btncancel_Click(object sender, System.EventArgs e)<br />
{<br />
if(MessageBox.Show("Do you want to exit","Exiting",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)<br />
Application.Exit();<br />
}<br />
<br />
private void btnnext_Click(object sender, System.EventArgs e)<br />
{<br />
Form2 objform2=new Form2(this);<br />
objform2.ShowDialog();<br />
}
form2:
------
<br />
private Form1 frmForm1;<br />
public Form2(Form1 objForm)<br />
{<br />
frmForm1=objForm;<br />
}<br />
private void btncancel_Click(object sender, System.EventArgs e)<br />
{<br />
if(MessageBox.Show("Do you want to exit","Exiting", MessageBoxButtons.OKCancel,MessageBoxIcon.Question) ==DialogResult.OK)<br />
Application.Exit();<br />
}<br />
<br />
private void butback_Click(object sender, System.EventArgs e)<br />
{<br />
frmForm1.Visible=true;<br />
this.Close();<br />
}<br />
<br />
private void Form2_Load(object sender, System.EventArgs e)<br />
{<br />
frmForm1.Visible=false;<br />
}<br />
|
|
|
|
|
Hi
What is my problem is if i click btcancel_clcik it will ask do you want to exit right?. In that message box(ok button and cancel button) if i click cancel i cant able to see any form.
kesavan
|
|
|
|
|
Hi
I solved the problem by changing showdialog to show.
i mean form1.showdialog() to form1.show()
Anyway thanks for spending your time for me
kesavan
|
|
|
|
|
Hi Friends
I would like to retrieve all the users from a particular Active Directory group. Can anyone tell me how to do this. I tried but i got this error:
There is no such object on the server
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: There is no such object on the server
This is my coding:
DirectoryEntry deGroup = new DirectoryEntry ("LDAP://cn=groupName,dc=itech,dc=com");
foreach(object oMember in deGroup.Properties["member"])
{
Response.Write(oMember.ToString());
}
|
|
|
|
|
hi!
whenever an click event of any control occurs in my C# asp.net web application(visual studio.net 2003), form load is called again and all controls are initialized. Like i m using check box in my grid and want to capture my check state against any button click. But when i click button then form is again loaded and all check boxex became converted in their default state(which is unchecked).
therefore the following condition in my button click event alwayx bacame false coz at that time no check box is in checked state.
the condition is
if(checkbox.checked)
i have many other problems also due to this from loading against any event. Therefore can u tell me how to stop this loading every time.
|
|
|
|
|
Hi,
Are you controlling if the PageLoad is from a postback (IsPostBack porperty)?
|
|
|
|
|
Check whether viewstate is disabled at any level.
Control/Page/Web.Config
|
|
|
|
|