Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am add the 0(Zeros)to sql table by using sql statement

select REPLICATE ('0',8-DATALENGTH (EmployeeCode ))+EmployeeCode as 'EmpCode' from TBL_DKCSV

But how to pass sqlcommnd in C#.net

Please help me..
Posted

C#
 string szQuery = "select REPLICATE ('0',8-DATALENGTH (EmployeeCode ))+EmployeeCode as 'EmpCode' from TBL_DKCSV"; //This might need some escaping

//Set connection to your database connection

SqlCommand cmd = new SqlCommand(szQuery, connection);

cmd.ExecuteNonQuery();
 
Share this answer
 
v2
If you are looking for a function in C# which is similar to REPLICATE in SQL server, you can use Padding strings[^]

If you are looking to show data from database in your application take a look at this article
Using ADO.NET for beginners[^]
 
Share this answer
 
v2
Hi dear,

private void FxREPLICATE()
{
  SqlConnection objConn1 = new SqlConnection("Data Source= Sql Server Name ;Initial Catalog= Database Name ;user id=sa; password=123;"); // Write you sql server database name and necessary option.
  string sql = "select REPLICATE ('0',8-DATALENGTH (EmployeeCode ))+EmployeeCode as 'EmpCode' from TBL_DKCSV";
  SqlCommand cmd = new SqlCommand(sql, objConn1);
  objConn1.Open();
  cmd.ExecuteNonQuery();
  objConn1.Close();
 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900