|
Why do you keep creating new threads about the same question all the time?
I have already explained exactly why your code is not working. I have also told you before that I already have explained why your code is not working.
Would you please read my reply before creating any more threads about this?
---
single minded; short sighted; long gone;
|
|
|
|
|
' i don't know which form is execute first
' what u do temperory
' first the form which is execute first write , first insert the values in database by using insert into tablename .... like wise.
' the information which u have only send in that function and leave it blank other field right. eg. insert into user (userid,password) values('viru_dram','hello')
' then in other form update the inserted value in database using eg.update tablename set timeout = system.datetime.now where userid='viru_dream' ....
'get it?. i will send u solution withing 2 days ok.bye.
|
|
|
|
|
Happy B'day!!
Form2 is execute first,its a login form.
After 'login' a 'grid form' opens,it has a logout button, on logout that datetime value must go in a table.
Thanx.
Take care
Enjoy d day!!
nekshan.
|
|
|
|
|
Hi,
I was wondering how to access a method in a form from another form. I know that this implies using the 'static' modifier, however, this seems to be very troublesome.
I was thinking there should be a way to access the instance of a form at realtime to use one of it's public methods.. (The form of which the method I want to call happens to be the main form of the application) Does anyone know how to do this? I'm stuck
Actually I was considering using the Observer Pattern for solving this problem, however I expect there should be a much more straight-forward solution..?
With kind regards,
Johan Vandewalle
-- modified at 6:06 Wednesday 21st February, 2007
|
|
|
|
|
motojojo wrote: I know that this implies using the 'static' modifier, however, this seems to be very troublesome.
No, it doesn't.
motojojo wrote: Actually I was considering using the Observer Pattern for solving this problem, however I expect there should be a much more straight-forward solution..?
The observer pattern is a good solution. You can get an example in this article about passing values between forms[^].
|
|
|
|
|
I hope someone can come up with a better method, but here is how I solve that problem.
In the second form, make a new function (or put it in the form's constructor) which accepts a form as its argument and stores it in a local variable (perhaps called mainform). From Main(), call this function and pass the main form.
Now, to call something withing the main form's class just use: mainform.mymethod();
Mark
|
|
|
|
|
thank you for your feedback guys I've worked around it
|
|
|
|
|
Hi.
I need to add the following line to the Http Header of a request to a web service:
"Accept: application/dime"
Do you have any suggestion on how to achieve that?
Very important: I use WSE 2.0.
Thanks in advance.
|
|
|
|
|
you can add some attribute as following :
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(Address);
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
req.Timeout = 60000;
req.KeepAlive = false;
req.Timeout = 60000;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
System.Text.Encoding enc = System.Text.Encoding.Default;
System.IO.Stream sm = res.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(sm,enc);
string strInput = sr.ReadToEnd();
i hope to find your answer
|
|
|
|
|
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
|
|
|
|