Hi Saiansh,
Refer below sample code and bind data to Telerik radCheckedlist List.
I have binded it to CheckBoxList.
HTML
<asp:CheckBoxList runat="server" ID="cblDB" AutoPostBack="true" OnSelectedIndexChanged="cblDB_SelectedIndexChanged">
</asp:CheckBoxList>
<asp:Label ID="Label1" runat="server" />
<asp:Label ID="Label2" runat="server" />
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT name,database_id from sys.databases", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
cblDB.DataSource = dt;
cblDB.DataTextField = "name";
cblDB.DataValueField = "database_id";
cblDB.DataBind();
}
}
}
}
}
public void BackupDatabase(string path, string dbName)
{
string name = dbName;
string fileUNQ = DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString();
name = name + fileUNQ + ".bak";
string backupPath = @"BACKUP DATABASE " + dbName + " TO DISK = N'" + path + @"\" + dbName + @"'";
string svr = "Server=" + " ServerName " + ";Database=" + dbName + ";UID=sa;PWD=pass@123";
SqlConnection con = new SqlConnection(svr);
SqlCommand cmd = new SqlCommand(backupPath, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Done";
Label2.Text = backupPath + "Server name " + " ServerName " + " Database " + dbName + " successfully backed up to " + path + @"\" + dbName + "\n Back Up Date : " + DateTime.Now.ToString();
}
catch (Exception ex)
{
Label1.Text = ex.ToString();
Label2.Text = backupPath + "Server name " + " ServerName " + " Database " + dbName + " successfully backed up to " + path + @"\" + dbName + "\n Back Up Date : " + DateTime.Now.ToString();
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
protected void cblDB_SelectedIndexChanged(object sender, EventArgs e)
{
BackupDatabase(@"D:\Backup\", cblDB.SelectedItem.Text);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT name,database_id from sys.databases", con)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
cblDB.DataSource = dt
cblDB.DataTextField = "name"
cblDB.DataValueField = "database_id"
cblDB.DataBind()
End Using
End Using
End Using
End If
End Sub
Public Sub BackupDatabase(ByVal path As String, ByVal dbName As String)
Dim name As String = dbName
Dim fileUNQ As String = DateTime.Now.Day.ToString() & "_" + DateTime.Now.Month.ToString() & "_" + DateTime.Now.Year.ToString() & "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() & "_" + DateTime.Now.Second.ToString()
name = name & fileUNQ & ".bak"
Dim backupPath As String = "BACKUP DATABASE " & dbName & " TO DISK = N'" & path & "\" & dbName & "'"
Dim svr As String = "Server=" & " ServerName " & ";Database=" & dbName & ";UID=sa;PWD=pass@123"
Dim con As SqlConnection = New SqlConnection(svr)
Dim cmd As SqlCommand = New SqlCommand(backupPath, con)
Try
con.Open()
cmd.ExecuteNonQuery()
Label1.Text = "Done"
Label2.Text = backupPath & "Server name " & " ServerName " & " Database " & dbName & " successfully backed up to " & path & "\" & dbName & vbLf & " Back Up Date : " & DateTime.Now.ToString()
Catch ex As Exception
Label1.Text = ex.ToString()
Label2.Text = backupPath & "Server name " & " ServerName " & " Database " & dbName & " successfully backed up to " & path & "\" & dbName & vbLf & " Back Up Date : " & DateTime.Now.ToString()
Finally
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Protected Sub cblDB_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
BackupDatabase("D:\Backup\", cblDB.SelectedItem.Text)
End Sub
Refer link for uploading files to ftp server.