Jayce Ooi's Paradise

Technology, mobile, photography, gaming, programming, anything

I want to insert a list of data that separated by comma like ’1234,2345,3456′ into a SQL table. How do I do that? Well, it is not hard if you know the trick. Here are the codes to do it.

DECLARE @pos int, @curruntLocation char(20), @input varchar(2048)
SELECT @pos=0
SELECT @input = ’1234,2345,3456′
SELECT @input = @input + ‘,’

CREATE TABLE #tempTable (temp varchar(100) )

WHILE CHARINDEX(‘,’,@input) > 0
BEGIN
SELECT @pos=CHARINDEX(‘,’,@input)
SELECT @curruntLocation = RTRIM(SUBSTRING(@input,1,@pos-1))
INSERT INTO #tempTable (temp) VALUES (@curruntLocation)
SELECT @input=SUBSTRING(@input,@pos+1,2048)
END

SELECT * FROM #tempTable

DROP TABLE #tempTable

Result – you will get 3 rows (1234,2345,3456) in #tempTable. The @input is your input variable. @curruntLocation is the value that needed to be inserted into SQL table. That’s it. :)

How to modify Windows System Registry Values with C#? As usual, you need to use Microsoft.Win32 Namespace ~ using Microsoft.Win32;. Let’s take Windows Application Event Logs values as an example. I want to change the MaxSize and Retention values in Application Event Log file by using C#.

Codes to change Windows System Registry values

RegistryKey TestEventLog = Registry.LocalMachine.OpenSubKey(“System\\CurrentControlSet\\Services\\EventLog\\Application”,true);
TestEventLog.SetValue(“MaxSize”, “102367232″, RegistryValueKind.DWord);
TestEventLog.SetValue(“Retention”, “0″, RegistryValueKind.DWord);

Above codes open Application event log and with write permission (,true). It changes both MaxSize and Retention values.
Just change the codes to suit your need. ;)

How to read and write Windows System Registry Keys and Values? I need to create a value at Windows System Registry for my project lately. It is used for SCOM discovery. I need a Windows System Registry key to determine that the server is the server that SCOM going to monitor.

First thing to do in your C#. Add using Microsoft.Win32; RegistryKey and Registry requires Microsoft.Win32 as the assembly reference.

Here are the codes that write Windows System Registry Keys.

RegistryKey JayceOoiKey = Registry.LocalMachine.CreateSubKey(“SOFTWARE\\JayceOoi”);

This will create key JayceOoi under HKEY_LOCAL_MACHINE\SOFTWARE\.

To read Test string value from HKEY_LOCAL_MACHINE\SOFTWARE\JayceOoi\

string Output = JayceOoiKey.GetValue(“Test”);

These are the methods that I use to read and write Windows System Registry Keys and Values. Hope it will help in your programming work. ;)

ASP.NET C# Input TextBox value by pressing Enter key. Huh? I want to get the value of the textbox without click on the submit button. But getting the textbox value by just pressing enter key on keyboard. How am I going to do so? The page just refresh if I press enter key. I want the enter key link to the submit button. Therefore, whenever I press enter key, I will get the textbox value.

Here is the solution to get it done. By adding defaultbutton variable in form or asp:Panel will solve it.

Code example

<form id=”form1″ defaultbutton=”Button1″ runat=”server”>
<div>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<asp:Button ID=”Button1″ runat=”server” Text=”Button” OnClick=”Button1_Click” />
<br />
<asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>
<asp:Panel ID=”Panel1″ defaultbutton=”Button2″ runat=”server”>
<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>
<asp:Button ID=”Button2″ runat=”server” Text=”Button” OnClick=”Button2_Click” />
<br />
<asp:Label ID=”Label2″ runat=”server” Text=”Label”></asp:Label>
</asp:Panel>
</div>
</form>




Featured ...






Guide for ...











Follow ...