|
As an alternative to what people have said, is there any sort of pre-population of the items in the combobox? If you're just populating the CB from items in a database, and you don't want things to repeat, just use DISTINCT in the query from the database (I'm assuming SQL here), and just use the combobox.displaymember, combobox.valuemember, and combobox.datasource to set it up.
|
|
|
|
|
hi I've a c# windows application in which I'm not using Application.Run to open the initial form instead I'm using show method to open up the form. Now to the problem when I catch an exception after some processing I want to terminate the application but with Applicatin.exit(), I'm not able to do so. I read somewhere on the net that the form which started through Application.Run can only be terminated by Application.exit. Is there any other method.
Thanks in advance.
Don't Quit
|
|
|
|
|
I would guess that if you started your application by calling the Show() method, you could terminate it by doing something like the following:
yourForm.Close();<br />
yourForm.Dispose();<br />
Why don't you use Application.Run() BTW?
|
|
|
|
|
Hi Thanks for your reply. Even this is not completely working. I need something that can terminate at that moment where it is called instantly without executing any code after that. Pls help me!
Thanks
Don't Quit
|
|
|
|
|
Try the following:
System.Diagnostics.Process.GetCurrentProcess().Kill();
It should instantly "kill" your app.
But keep in mind that objects would probably not be disposed and released when you do that.
Regards,
Shy.
|
|
|
|
|
how to burn data in c#
i don't need simply write
i need a program to pro write ,write cd-fs and ..
|
|
|
|
|
|
Hellow to all ...
i am trying to run an SQL statment on my DB database i wanna pick from the statment a field after inserting i tried to run this code but i always recive this error " Multiple-step OLE DB operation generated errors .... "
string SQLContract;
int ContractIndx;
ClsInfo Assist_Var = new ClsInfo();
try
{
SQLContract = "INSERT Contract( " +
"ClientNum,ContractType,BDate,EDate," +
"UDate,PDate,ContratOption,PropertyNum,"+
"HierMeters,MeterPrice,Remarks)" +
"VALUES( " +
txt_Client_Name.Text + "," +
Assist_Var.PrepareStr("B") + "," +
Assist_Var.PrepareStr(dtFromDate.Text) + "," +
Assist_Var.PrepareStr(dtToDate.Text) + "," +
Assist_Var.PrepareStr(dtChange.Text) + "," +
Assist_Var.PrepareStr(dtLastPay.Text) + "," +
Assist_Var.Val(txtYears.Text) + "," +
Assist_Var.Val(txtPropertyID.Text) + "," +
Assist_Var.Val(txtMeters.Text) + "," +
Assist_Var.Val(txtMeterPrice.Text) + "," +
Assist_Var.PrepareStr(txtRemarks.Text) + "); " +
"SELECT @Indx = @@IDENTITY" ;
OleDbConnection OleDbConn = new OleDbConnection(Assist_Var.SQLConnection());
OleDbConn.Open();
OleDbCommand OleDbCommand = new OleDbCommand();
OleDbCommand.CommandText = SQLContract;
OleDbCommand.CommandType = CommandType.Text;
OleDbCommand.Connection = OleDbConn;
OleDbParameter MyPara = new OleDbParameter();
MyPara = new OleDbParameter("@Indx",OleDbType.Integer , 4);
MyPara.Direction = ParameterDirection.Output;
OleDbCommand.Parameters.Add(MyPara);
OleDbCommand.ExecuteNonQuery();
ContractIndx = Convert.ToInt32(OleDbCommand.Parameters["@Indx"].Value);
MessageBox.Show(ContractIndx.ToString());
OleDbConn.Close();
OleDbConn.Dispose();
OleDbCommand.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
thxx to u ...
|
|
|
|
|
OK this is obviously a SQL Server statement, so why aren't you using the Sql... classes? They don't use the ODBC classes, so are more performant (plus they will avoid this error).
Also, you should probably use a Stored Procedure to do this and remove the gaping security hole you have here. Don't use direct text statements because they are wide open to SQL Injection attacks.
BTW - you missed the most important piece of information about your error - the actual error code. This error is fairly generic, and the error code (the 800... one) is useful for identifying the actual error that triggered it.
One final thought - don't use @@IDENTITY. This is not guaranteed to return you the last identity because if you have a trigger on the table that performs an insert into a different table with an identity column on it, @@IDENTITY will return the identity of that table instead. Use SCOPE_IDENTITY() instead.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
ok Pete so what do u suggest that i should do ...
where do i find all the things that u told me about ?
thank u ...
|
|
|
|
|
|
i saw the linkes that i gave me i don't see anything that i am doing wrong ..
and if i validate the data in the forms befor i run the sql statment i can skep the injection attacks part ..
|
|
|
|
|
microuser_2000 wrote: if i validate the data in the forms befor i run the sql statment i can skep the injection attacks part ..
Not really no. Don't think you can outwit a clever attacker. Personally, I believe that if I sufficiently sanitise the input then I won't be attacked. But, I am not infallible (no one is, not even you!) so I still use parameterised queries as an extra safety mechanism. It doesn't cost me anything, the code actually looks cleaner and easier to read and I have extra safety. Also, in some database systems using the same parameterised query, but just changing the parameter values means you get faster query execution too because it doesn't have to recompile the SQL each time.
Only give up safety if there are tangible benefits. Better safe than sorry.
|
|
|
|
|
yaa , i will try it ..
anyway ..
anyone have idea how can i pick the value that i had insert to a table ..
i use the code that i show in the first message of this post in VB.NET and it work's fine .
i don't know why in CS it don't work ...
|
|
|
|
|
Hello,
how can I use a value type in a generic method constraint? Is it at all possible?
Obviously,
public static T1 GenericMethod<T1>(T1 input) where T1: int, double, decimal
won't work.
Thanks,
Michal
|
|
|
|
|
public static T1 GenericMethod(T1 input)
where T1 : struct
{
}
|
|
|
|
|
Ok, thanks, but I assume that all value types are comparable, however the following example code doesn't compile with "where T1: struct":
public static T1 GenericMethod<T1>(T1 value1, T1 value2) where T1: struct
{
if (value1 > value2)
{
return value1;
}
return value2;
}
So there must be some other way to restrict T1 just to value types.
Thanks,
Michal
|
|
|
|
|
How about this?
public static T1 GenericMethod<T1>(IComparable<T1> value, IComparable<T1> value2)
where T1 : struct
{
}
|
|
|
|
|
Doesn't work, unfortunately:
public static T1 GenericMethod<T1>(IComparable<T1> value1, IComparable<T1> value2) where T1 : struct
{
if (value1 > value2)
{
return value1;
}
return value2;
}
is producing this error:
Operator '>' cannot be applied to operands of type 'System.IComparable<T1>' and 'System.IComparable<T1>'
It doesn't help to use "where T1: struct, IComparable" neither.
Michal
|
|
|
|
|
Yes, don't use the greater-than or less-than operator to compare the values, since not all IComparable objects implement those operator methods (seems silly they don't, IMO). Instead, use this:
if(value1.CompareTo(value2) > 0)
{
return value1;
}
return value2;
|
|
|
|
|
Thanks for the hint!
The final compilable notation would be this:
public static T1 GenericMethod<T1>(IComparable<T1> value1, IComparable<T1> value2) where T1 : struct
{
if (value1.CompareTo((T1)value2) > 0)
{
return (T1)value1;
}
return (T1)value2;
}
Michal
|
|
|
|
|
How do i capture the events in the datagrid header text?
actually i have to sort the datagrid column when an image is click on the header of the datagrid column?
people laugh at me because they say im different and I laugh at them because they are all the same.
|
|
|
|
|
sundar156 wrote: How do i capture the events in the datagrid header text?
Handle the ColumnHeaderMouseClick event.
/ravi
|
|
|
|
|
Hello everyone:
I've created a TxtBox with vertibal bar enable and Button. When user click on Button and and browse to select any file, that file would get store on that txtbox.
I dont know how to started. Could someone please provide some sample code that I could work with?
Thanks,
Eyungwa
-- modified at 13:18 Wednesday 7th February, 2007
|
|
|
|
|
myTextBox.Text = File.ReadAllText ("C:\\myfile.txt"); /ravi
|
|
|
|