Public Sub ClearTextBoxes(ByVal f As Form)
Dim meuForm As Type = f.GetType()
Dim campos As Reflection.FieldInfo() = meuForm.GetFields(Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
For Each campo As Reflection.FieldInfo In campos
If campo.FieldType.Name.ToLower = "textbox" Then
Dim t As TextBox = DirectCast(campo.GetValue(f), TextBox)
t.Text = ""
End If
Next
End Sub
Wednesday, March 4, 2009
Tuesday, December 2, 2008
Using Crystal Reports in ASP .NET
Imports CrystalDecisions.CrystalReports.Engine
Dim ds as new Dataset
'Fill the dataset using Data adapter
Dim rep As New ReportDocument
rep.Load(Server.MapPath("CrystalReport1.rpt"))
rep.setDatasource(ds)
CrystalReportViewer1.ReportSource = rep
Dim ds as new Dataset
'Fill the dataset using Data adapter
Dim rep As New ReportDocument
rep.Load(Server.MapPath("CrystalReport1.rpt"))
rep.setDatasource(ds)
CrystalReportViewer1.ReportSource = rep
Thursday, November 20, 2008
MS SQL Restore and Backup code using .NET
First add a reference of Microsoft SQLDMO Object Library from COM tab .Then Write the below code
//Function for Restore
private void Restore()
{
try
{
this.Cursor = Cursors.WaitCursor;
//create an instance of a server class
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
//connect to the server
srv.Connect("(local)","sa",""); //srv.Connect(servername,userid,password)
//create a restore class instance
SQLDMO.Restore res = new SQLDMO.RestoreClass();
//set the backup device = files property ( easy way )
res.Devices = res.Files;
//set the files property to the File Name text box
res.Files =textBox1.Text;//give full path with restore filename
//set the database to the chosen database
res.Database = "databaseName";
// Restore the database
res.ReplaceDatabase = true;
res.SQLRestore(srv);
MessageBox.Show("Database restored successfully.", "Restore Successfull");
this.Cursor = Cursors.Default;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"Error");
}
}
//Function for Backup
private void BackUp()
{
try
{
Class1.con.Close();
this.Cursor = Cursors.WaitCursor;
//create an instance of a server class
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
//connect to the server
srv.Connect("(local)","sa",""); //srv.Connect(servername,userid,password)
//create a backup class instance
SQLDMO.Backup bak = new SQLDMO.BackupClass();
//set the backup device = files property ( easy way )
bak.Devices = bak.Files;
//set the files property to the File Name text box
//
bak.Files = this.textBox1.Text;//give full path with bakup filename
//set the database to the chosen database
bak.Database = "databasename";
//perform the backup
bak.SQLBackup(srv);
MessageBox.Show("Database successfully backed up.", "Backup Successfull");
this.Cursor = Cursors.Default;
}
catch(Exception err)
{
this.Cursor = Cursors.Default;
MessageBox.Show(err.Message,"Error");
}
}
//Function for Restore
private void Restore()
{
try
{
this.Cursor = Cursors.WaitCursor;
//create an instance of a server class
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
//connect to the server
srv.Connect("(local)","sa",""); //srv.Connect(servername,userid,password)
//create a restore class instance
SQLDMO.Restore res = new SQLDMO.RestoreClass();
//set the backup device = files property ( easy way )
res.Devices = res.Files;
//set the files property to the File Name text box
res.Files =textBox1.Text;//give full path with restore filename
//set the database to the chosen database
res.Database = "databaseName";
// Restore the database
res.ReplaceDatabase = true;
res.SQLRestore(srv);
MessageBox.Show("Database restored successfully.", "Restore Successfull");
this.Cursor = Cursors.Default;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"Error");
}
}
//Function for Backup
private void BackUp()
{
try
{
Class1.con.Close();
this.Cursor = Cursors.WaitCursor;
//create an instance of a server class
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
//connect to the server
srv.Connect("(local)","sa",""); //srv.Connect(servername,userid,password)
//create a backup class instance
SQLDMO.Backup bak = new SQLDMO.BackupClass();
//set the backup device = files property ( easy way )
bak.Devices = bak.Files;
//set the files property to the File Name text box
//
bak.Files = this.textBox1.Text;//give full path with bakup filename
//set the database to the chosen database
bak.Database = "databasename";
//perform the backup
bak.SQLBackup(srv);
MessageBox.Show("Database successfully backed up.", "Backup Successfull");
this.Cursor = Cursors.Default;
}
catch(Exception err)
{
this.Cursor = Cursors.Default;
MessageBox.Show(err.Message,"Error");
}
}
Saturday, November 15, 2008
Using Date Field in .NET when using with MS Access
Use #"+dateTimePicker1.Values+"# instead of '"+dateTimePicker1.Values+"'
This type is only used when retriving values using date or updating using date or deleting using date
NOTE: This type is not used while inserting datas to table
Inserting single quotes to a string in sql query
Just Add one more single quotes to that string by the user
eg: insert into table name values('D''zousa')
or
The programmer has to maintain that one using coding
Means we have to check the string if a single quotes exists or not.
If exists we have to add one more single quotes to that string.s
eg: insert into table name values('D''zousa')
or
The programmer has to maintain that one using coding
Means we have to check the string if a single quotes exists or not.
If exists we have to add one more single quotes to that string.s
GETTING VALUES FROM DATASET
GETTING VALUES FROM DATASET
txtName.text = ds.Tables(0).Rows(row).Item(1)
Making Changes to Dataset Manually
ds.Tables(0).Rows(row).Item(1) = dt1.Value.ToShortTimeString()
ds.Tables(0).Rows(row).Item(2) = dt2.Value.ToShortTimeString()
ds.Tables(0).Rows(row).Item(3) = dt3.Text
ds.Tables(0).Rows(row).Item(4) = dt4.Text
ds.Tables(0).Rows(row).Item(5) = fin.Hours
ds.Tables(0).Rows(row).Item(6) = fin.Minutes
This is one method.There are so many other methods also; by using DataRow and DataTable etc..
txtName.text = ds.Tables(0).Rows(row).Item(1)
Making Changes to Dataset Manually
ds.Tables(0).Rows(row).Item(1) = dt1.Value.ToShortTimeString()
ds.Tables(0).Rows(row).Item(2) = dt2.Value.ToShortTimeString()
ds.Tables(0).Rows(row).Item(3) = dt3.Text
ds.Tables(0).Rows(row).Item(4) = dt4.Text
ds.Tables(0).Rows(row).Item(5) = fin.Hours
ds.Tables(0).Rows(row).Item(6) = fin.Minutes
This is one method.There are so many other methods also; by using DataRow and DataTable etc..
CODE FOR POPULATING COMBOBOX USING DATASET
Dim ds as new Dataset
Dim sda as new OleDBDataAdapter("write query here",connection)
sda.Fill(ds,"tablename")
With cmbEOS
.DataSource = ds.Tables("Tablename")
.ValueMember = "fieldname
End With
Dim sda as new OleDBDataAdapter("write query here",connection)
sda.Fill(ds,"tablename")
With cmbEOS
.DataSource = ds.Tables("Tablename")
.ValueMember = "fieldname
End With
Subscribe to:
Posts (Atom)