CREATE TABLE TableB (
PK1 INT NOT NULL,
PK2 INT NOT NULL,
SomeData VARCHAR(1000),
CONSTRAINT PK_TableB PRIMARY KEY CLUSTERED (PK1, PK2)
)
CREATE TABLE TableA (
PK INT NOT NULL,
FK1 INT NOT NULL, -- Or NULL, if you''d rather.
FK2 INT NOT NULL,
CONSTRAINT PK_TableA PRIMARY KEY CLUSTERED (PK),
CONSTRAINT FK_TableA_FK1FK2 FOREIGN KEY (FK1, FK2) REFERENCES TableB (PK1, PK2),
CONSTRAINT Cons2cols UNIQUE(FK1, FK2)
)
Thursday, July 17, 2014
Add a unique constraint of a sql table as foreign key reference to an another sql table
Saturday, June 28, 2014
C# Text box only allow two decimal points and numbers using text box keypress event
private void txtScore_KeyPress(object
sender, KeyPressEventArgs e)
{
if
((e.KeyChar < '0' || e.KeyChar > '9') && (e.KeyChar != '\b') && (e.KeyChar != '.'))
{
e.Handled = true;
}
else
{
e.Handled = false;
}
if
(Char.IsControl(e.KeyChar))
{
e.Handled = false;
}
else
if (Char.IsNumber(e.KeyChar)
|| e.KeyChar == '.')
{
TextBox
tb = sender as TextBox;
int
cursorPosLeft = tb.SelectionStart;
int
cursorPosRight = tb.SelectionStart + tb.SelectionLength;
string
result = tb.Text.Substring(0, cursorPosLeft) + e.KeyChar + tb.Text.Substring(cursorPosRight);
string[]
parts = result.Split('.');
if
(parts.Length > 1)
{
if
(parts[1].Length > 2 || parts.Length > 2)
{
e.Handled = true;
}
}
}
}
Monday, June 23, 2014
Friday, June 20, 2014
C#.NET - How to open windows application form from winword using Com objects ( Macro)
Step 1
1.
Add Class
Library name "WordConnector"
Step 2
Rename Class1.cs
as "clsConnector.cs"
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace WordConnector
{
public class clsConnector
{
public void Start(Word.Document objDocument)
{
new
frmWord(objDocument).Show();
}
}
}
----------------------------------------
Add form rename as "frmWord.cs"
-------------------------------------------------
using System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
WordConnector
{
public partial class frmWord : Form
{
string
sDocumentName = string.Empty;
public
frmWord()
{
InitializeComponent();
}
public
frmWord(Word.Document objDocument)
{
InitializeComponent();
this.sDocumentName
= objDocument.Name.ToString();
this.Text
= sDocumentName.Replace(".doc", string.Empty).ToUpper();
}
}
}
Step 3
Step 4
Click on Assembly
Information button
Step 5
Check Make assembly COM-Visible
Step 6
Click Build and
Scroll down check Register for COM interop.
Step 7
Click Signing menu
Step 8
1. Check sign the assembly.
2. Click choose a strong name key file combo box <New>
Step 9
Give key file name as "Key_WordConnector"
Step 10
Copy
WordConnector.dll and WordConnector.tlb from project bin
folder
Step 11
Pate WordConnector.dll and WordConnector.tlb in " C:\WINDOWS\system32"
Step 12
1. Open winword document and Press Alt+F11
2. Write macro in module.
3.Click Tools -> References - >
5. Browse for WordConnector.tlb
Check Wordconnector
Add this macro in module
Press F8 and see form will open from worddocument
Wednesday, June 18, 2014
MSSQL - Getting all dates between from date and to date.
declare @col nvarchar(max)
declare @query nvarchar(max)
declare @StartDate
as date
declare @EndDate as date
set @StartDate
= '2014-06-01'
set @EndDate = '2014-06-18'
IF OBJECT_ID('tempdb..#TempTable') IS NOT NULL DROP TABLE #TempTable
create TABLE #TempTable
(
Rep_Date date
)
while @StartDate
<= @EndDate
begin
insert into #TempTable (Rep_Date) values(@StartDate)
set @StartDate
= DATEADD(dd,1,@StartDate)
end
select * from #TempTable
drop table
#TempTable
Saturday, June 14, 2014
C#.NET - BackgroundWorker that accepts more than one argument.
Class MyClass
{
private string m_Username = string.Empty;
private int m_Targetnumber;
public MyClass(){}
public string Username
{
get { return m_Username; }
set { m_Username = value; }
}
public int TargetNumber
{
get { return m_TargetNumber; }
set { m_TargetNumber = value; }
}
}
// setup/init:
BackgroundWorker startCallWorker = new BackgroundWorker();
startCallWorker.DoWork += new DoWorkEventHandler(StartCallWorker_DoWork);
...
MyClass thisClass = new MyClass();
thisClass.Username = "abcd";
thisClass.TargetNumber = 1234;
startCallWorker.RunWorkerAsync(thisClass);
// the handler:
private void StartCallWorker_DoWork(object sender, DoWorkEventArgs e)
{
MyClass args = (MyClass)e.Argument;
string userName = args.Username;
string targetNumber = args.TargetNumber;
}
Thursday, June 12, 2014
MSSQL - Communicating one database to another using opendatasource
Communicating one database to another using opendatasource.
Example;
select UserId , Username , EmployeeId
from OPENDATASOURCE('SQLOLEDB', 'Data Source=172.166.10.116;
User ID=sa;Password=12345678').hrms.dbo.employee_list
Subscribe to:
Posts (Atom)