The below method is used to bulk insert in to a table by using c# from a datatable.
using System.Data;
using System.Data.SqlClient;
public int BulkInsert(DataTable dt, string TableName, string ConnectionString)
{
int returnValue = -1;
SqlConnection oConn = new SqlConnection(ConnectionString);
oConn.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM " + TableName,oConn);
da.SelectCommand.Connection = oConn;
DataSet ds = new DataSet();
SqlCommandBuilder oCmd = new SqlCommandBuilder(da);
try
{
da.Fill(ds);
returnValue = da.Update(dt);
}
catch (Exception ex)
{
throw ex;
}
finally
{
oConn.Close();
oCmd.Dispose();
}
return returnValue;
}
...S.VinothkumaR.
Copy All Directories with Files using C#
Here is the sample code for copying a directory with sub directories and all the files using C#.
public static void CopyAllDirectories(DirectoryInfo source, DirectoryInfo target)
{
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
foreach (FileInfo fileInfo in source.GetFiles())
{ fileInfo.CopyTo(Path.Combine(target.ToString(),fileInfo.Name), true);
}
foreach (DirectoryInfo sourceSubDir in source.GetDirectories())
{
DirectoryInfo targetSubDir =
target.CreateSubdirectory(sourceSubDir.Name);
CopyAllDirectories (sourceSubDir, targetSubDir);
}
}
...S.VinothkumaR.
public static void CopyAllDirectories(DirectoryInfo source, DirectoryInfo target)
{
if (Directory.Exists(target.FullName) == false)
{
Directory.CreateDirectory(target.FullName);
}
foreach (FileInfo fileInfo in source.GetFiles())
{ fileInfo.CopyTo(Path.Combine(target.ToString(),fileInfo.Name), true);
}
foreach (DirectoryInfo sourceSubDir in source.GetDirectories())
{
DirectoryInfo targetSubDir =
target.CreateSubdirectory(sourceSubDir.Name);
CopyAllDirectories (sourceSubDir, targetSubDir);
}
}
...S.VinothkumaR.
Scrollbar in down side of textbox.
Scrollbar in down side of textbox.
Hi all, I have come to give a very simple solution for the below question. The question is
How to set scrollbar in end of the text in textbox when dynamically updating the text value?
Actually I have been developing a big application. On that application I needed to update the status of every action in my application. For the purpose of updating the status, I have used the textbox to show the status with multiline and vertical scrollbar properties. But I could see the vertical bar not going down when updating the status as shown in the below figure which is marked in red.
After googling few minutes I found we have some properties and methods in textboxes of visual studio are SelectionStart and ScrollToCaret method.
By using the above property and method I have found the solution for my question. See the below figure...
Code Snippet:
private void btnUpdate_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtStatus.Text))
txtStatus.Text = txtStatus.Text + Environment.NewLine;
txtStatus.Text = txtStatus.Text + "Status Updated...";
txtStatus.SelectionStart = txtStatus.Text.Length;
txtStatus.ScrollToCaret();
txtStatus.Refresh();
}
...S.VinothkumaR.
Hi all, I have come to give a very simple solution for the below question. The question is
How to set scrollbar in end of the text in textbox when dynamically updating the text value?
Actually I have been developing a big application. On that application I needed to update the status of every action in my application. For the purpose of updating the status, I have used the textbox to show the status with multiline and vertical scrollbar properties. But I could see the vertical bar not going down when updating the status as shown in the below figure which is marked in red.
After googling few minutes I found we have some properties and methods in textboxes of visual studio are SelectionStart and ScrollToCaret method.
By using the above property and method I have found the solution for my question. See the below figure...
Code Snippet:
private void btnUpdate_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtStatus.Text))
txtStatus.Text = txtStatus.Text + Environment.NewLine;
txtStatus.Text = txtStatus.Text + "Status Updated...";
txtStatus.SelectionStart = txtStatus.Text.Length;
txtStatus.ScrollToCaret();
txtStatus.Refresh();
}
...S.VinothkumaR.
Subscribe to:
Posts (Atom)