SQL, C#, VB, .net, asp, JavaScript, you name it. Code samples, Error messages and stuff like that. Please add coments if you think I said something stupid :D or if you have a better idea ... or anything at all ...
Friday, September 3, 2010
Tuesday, August 31, 2010
Textbox validate characters digits only - Desktop App
I wanted to let the user enter onlydigits in a Textbox and validate the characters when the types.
I came up with this:
private void numericUpDown_Count_KeyPress(object sender, KeyPressEventArgs e)
{
if ("1234567890".IndexOf(e.KeyChar.ToString()) > 0)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
tell me if there's an easier way :)
I came up with this:
private void numericUpDown_Count_KeyPress(object sender, KeyPressEventArgs e)
{
if ("1234567890".IndexOf(e.KeyChar.ToString()) > 0)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
tell me if there's an easier way :)
Wednesday, June 16, 2010
Citrix: how do you ctrl + alt + delete ?
in Citrix, the ctrl + alt + delete can be done like this:
ctrl + f1
ctrl + f1
Tuesday, May 11, 2010
The ConnectionString property has not been initialized
I had this error:
The ConnectionString property has not been initialized.
I have a MSI installer, that is installed in our QA environment.
It was working before, and suddenly, I only had this error.
Googled up a bit, all this info on how to get the connection string and all that.
I finally realized that I rebuilt the whole solution, but I didn't rebuild the Deployment project. After a rebuild ... everything back to normal.
#:-S
Hope this helps someone.
The ConnectionString property has not been initialized.
I have a MSI installer, that is installed in our QA environment.
It was working before, and suddenly, I only had this error.
Googled up a bit, all this info on how to get the connection string and all that.
I finally realized that I rebuilt the whole solution, but I didn't rebuild the Deployment project. After a rebuild ... everything back to normal.
#:-S
Hope this helps someone.
Thursday, April 1, 2010
Gridview nowrap
What do you do when you have
AllowPaging="False" AllowSorting="False" AutoGenerateColumns="True" Width="800px" ShowHeader="true"
And it wraps all your data?
you add:
OnRowDataBound="GridView_RowDataBound"
and then:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
}
}
AllowPaging="False" AllowSorting="False" AutoGenerateColumns="True" Width="800px" ShowHeader="true"
And it wraps all your data?
you add:
OnRowDataBound="GridView_RowDataBound"
and then:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
}
}
Tuesday, March 2, 2010
Enum to DataTable
I had a lot of ENUM-s and needed to make DataTable - s with the same structure for pretty much all of them.
I came up with this:
private static DataTable CreateDataTable < TheSQLtable > ()
{
Type t = typeof(TheSQLtable);
if (!t.IsEnum)
{
throw new InvalidOperationException("Type is not Enum");
}
DataTable dt = new DataTable();
dt.TableName = t.Name;
DataColumn dc;
string[] names = Enum.GetNames(t);
foreach (string name in names)
{
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.String");
dc.ColumnName = name;
dc.Unique = false;
dt.Columns.Add(dc);
}
return dt;
}
(with a little help from stackoverflow)
I came up with this:
private static DataTable CreateDataTable < TheSQLtable > ()
{
Type t = typeof(TheSQLtable);
if (!t.IsEnum)
{
throw new InvalidOperationException("Type is not Enum");
}
DataTable dt = new DataTable();
dt.TableName = t.Name;
DataColumn dc;
string[] names = Enum.GetNames(t);
foreach (string name in names)
{
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.String");
dc.ColumnName = name;
dc.Unique = false;
dt.Columns.Add(dc);
}
return dt;
}
(with a little help from stackoverflow)
Wednesday, February 24, 2010
How to check in C# if a DataRow is Empty. (nothing in any column)
I was hoping i find something like dr.isEmpty(), but there's nothing "this nice". So you do something plain like:
bool AreAllColumnsEmpty(DataRow dr)
{
if (dr == null)
{
return true;
}
else
{
foreach(var value in dr.ItemArray)
{
if (value != null)
{
if (value.ToString() != "")
{
return false;
}
}
}
return true;
}
}
bool AreAllColumnsEmpty(DataRow dr)
{
if (dr == null)
{
return true;
}
else
{
foreach(var value in dr.ItemArray)
{
if (value != null)
{
if (value.ToString() != "")
{
return false;
}
}
}
return true;
}
}
Subscribe to:
Posts (Atom)