Click here to Skip to main content
16,018,664 members

Comments by arun.emm (Top 9 by date)

arun.emm 16-Feb-12 7:54am View    
Here's my coding..
SqlTransaction OraTrans = null;
string sNoOfRecAff = null;
string sDBPath = Application.StartupPath + "\\DB\\SKTDB.mdf";
if (System.IO.File.Exists(sDBPath))
{
strConnString = "Data Source=.\\SQLEXPRESS;AttachDbFilename='" + sDBPath + "';User ID=sa;Password=1234";
}
string strSQL = "INSERT INTO EmpDetails(StaffCode, FirstName, LastName, Gender, DOB, Age, Father_Hus_Name, Address, Mobileno, Experience, prevCompAdd, DOJ, Designation, BasicSalary) VALUES(" + txt_code.Text + ",'" + txt_fname.Text + "','" + txt_lname.Text + "','" + g + "','" + dob + "','" + txt_age.Text + "','" + txt_father.Text + "','" + txt_addr.Text + "','" + txt_mobile.Text + "','" + cb_exp.SelectedItem.ToString() + "','" + txt_previousco.Text + "','" + doj + "','" + txt_desig.Text + "','" + txt_basic.Text + "')";

try
{
myConn = new SqlConnection(strConnString); myConn.Open(); OraTrans = myConn.BeginTransaction();
//myCmd.Transaction = OraTrans;
myCmd = new SqlCommand(strSQL, myConn, OraTrans);
sNoOfRecAff = myCmd.ExecuteNonQuery().ToString();
OraTrans.Commit();
OraTrans.Dispose();
return sNoOfRecAff;
}
catch (Exception ex)
{
OraTrans.Rollback();
return ex.Message;
}
finally
{
myConn.Close();
myCmd.Dispose();
myConn.Dispose();
}

is this a right way to do it?..
arun.emm 16-Feb-12 7:49am View    
Here's my coding..

SqlTransaction OraTrans = null;
string sNoOfRecAff = null;
string sDBPath = Application.StartupPath + "\\DB\\SKTDB.mdf";
if (System.IO.File.Exists(sDBPath))
{
strConnString = "Data Source=.\\SQLEXPRESS;AttachDbFilename='" + sDBPath + "';User ID=sa;Password=1234";
}
string strSQL = "INSERT INTO EmpDetails(StaffCode, FirstName, LastName, Gender, DOB, Age, Father_Hus_Name, Address, Mobileno, Experience, prevCompAdd, DOJ, Designation, BasicSalary) VALUES(" + txt_code.Text + ",'" + txt_fname.Text + "','" + txt_lname.Text + "','" + g + "','" + dob + "','" + txt_age.Text + "','" + txt_father.Text + "','" + txt_addr.Text + "','" + txt_mobile.Text + "','" + cb_exp.SelectedItem.ToString() + "','" + txt_previousco.Text + "','" + doj + "','" + txt_desig.Text + "','" + txt_basic.Text + "')";
try
{
myConn = new SqlConnection(strConnString);
myConn.Open();
OraTrans = myConn.BeginTransaction();
//myCmd.Transaction = OraTrans;
myCmd = new SqlCommand(strSQL, myConn, OraTrans);
sNoOfRecAff = myCmd.ExecuteNonQuery().ToString();
OraTrans.Commit();
OraTrans.Dispose();
return sNoOfRecAff;
}

catch (Exception ex)
{
OraTrans.Rollback();
return ex.Message;
}

finally
{
myConn.Close();
myCmd.Dispose();
myConn.Dispose();
}
arun.emm 16-Feb-12 7:29am View    
Hi Rahul ,
Thanks for your reply.. But i dont want to create database and tables in sql management studio. I want to create database within the application folder using server explorer of vs 2008. And i've created it already but got a problem which i have stated above.
arun.emm 20-Sep-11 7:03am View    
Hi ,

select emp_Code, [Dates], [1] intime ,[2] break_out,[3] break_in,[4] outtime
from
(select emp_code,convert(date,[DATES]) [date],convert(time,[times]) time ,ROW_NUMBER() over(partition by emp_code,dates order by emp_code,dates) Tin from punch_details
)data
pivot
(
max([times])
for Tin in ([1],[2],[3],[4])
)p

the above query returns the following error ,
"Incorrect syntax near 'pivot'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the stored procedure sp_dbcmptlevel".
arun.emm 20-Sep-11 7:01am View    
Deleted
Hi ,
select emp_Code, [Dates], [1] intime ,[2] break_out,[3] break_in,[4] outtime
from
(select empcode,convert(date,[DATES]) [date],convert(time,[times]) time ,ROW_NUMBER() over(partition by emp_code,dates order by emp_code,dates) Tin from punch_details
)data
pivot
(
max([times])
for Tin in ([1],[2],[3],[4])
)p

the above query returns the following error ,
"Incorrect syntax near 'pivot'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the stored procedure sp_dbcmptlevel".