Rahul Krishnan R
Wednesday, September 22, 2010
Cannot access Windows XP PC from windows 7 PC in the same network [ SOLVED ]
In Windows 7 box, do the following :
Type secpol.msc in RUN.
Select Local Policy -> Security Options.
Then select
" Network Security : LAN Manager authentication level "
Edit that policy and select
"Send LM & NTLM - use NTLMv2 session security if negotiated"
Done.
Monday, September 13, 2010
SQL Update query using Inner Join
update
t1
set
t1.sellingprice=t2.sp
from
Table_1 t1
inner join Table_2 t2
on
t1.itemid=t2.itemid
where
t1.itemid=t2.itemid
Sunday, September 12, 2010
Update statement to update multiple SQL tables simultaneously ( c# windows form)
There are two ways to handle this :
Method 1
SqlConnection conn =
new
SqlConnection(
"connection string goes here"
);
try
{
SqlCommand cmd =
new
SqlCommand();
cmd.Connection = conn;
// write your condition here instead of true
if
(
true
)
{
// you can also execute multiple commands here instead of one
// SQL Server allows multiple statements whereas Oracle does not
// Or write a procedure to do this
cmd.CommandText = @"UPDATE YourTable1 SET SomeColumn=@param1;
UPDATE YourTable2 SET SomeColumn=@param2;";
cmd.Parameters.AddRange(
new
SqlParameter[]
{
new
SqlParameter()
{
ParameterName =
"@param1"
,
Value =
"your value"
,
DbType = DbType.String
},
new
SqlParameter()
{
ParameterName =
"@param2"
,
Value =
"your value"
,
DbType = DbType.String
}
});
conn.Open();
cmd.ExecuteNonQuery();
}
}
catch
{
// Handle exception here
}
finally
{
if
(conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
}
Method 2
view plain
copy to clipboard
print
?
SqlConnection conn =
new
SqlConnection(
"your conn string here"
);
SqlTransaction trans;
SqlCommand cmd1 =
new
SqlCommand(
"UPDATE Table1 SET Column1=Value1"
,conn,trans);
SqlCommand cmd2 =
new
SqlCommand(
"UPDATE Table2 SET Column2=Value2"
,conn,trans);
if
(condition1)
{
conn.Open();
trans = conn.BeginTransaction();
try
{
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
trans.Commit();
conn.Close();
}
catch
(Exception ex)
{
trans.Rollback();
}
finally
{
if
(conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}
else
{
//do something else
}
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)