ada edit delete
TRANSCRIPT
-
8/14/2019 ADA Edit Delete
1/18
-
8/14/2019 ADA Edit Delete
2/18
MySqlConnection Class is used to connect to MySQL database.
Dim con As MySqlConnection = New MySqlConnection("Data
Source=localhost;Database=test;User ID=root;Password=mysql;")
Diaplay Records in DataGridview from MySQL Database.Display Records in
VB.Net from MySQL Database
Private Sub DisplayRecords_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim con As MySqlConnection = New MySqlConnection("Data
Source=localhost;Database=test;User ID=root;Password=mysql;")
Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROMuserreg", con)
Dim ds As DataSet = New DataSet()
Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
con.Open()
DataAdapter1.SelectCommand = sql
DataAdapter1.Fill(ds, "Product")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Product"
con.Close()
End Sub
Insert Records in MySql Database.
Private Sub AddRecords_Click(ByVal sender As System.Object, ByVal e As
-
8/14/2019 ADA Edit Delete
3/18
System.EventArgs) Handles Button2.Click
Dim Query As String
'Query = "INSERT INTO userreg"
Dim con As MySqlConnection = New MySqlConnection("Data
Source=localhost;Database=test;User ID=root;Password=mysql;")
'Dim sql As MySqlCommand = New MySqlCommand(Query, con)
Query = "INSERT INTO userreg(idUserReg,UserName, Age)VALUES("
Query = Query + txtUserRegId.Text + ",'" + txtUserName.Text + "',"
+ txtAge.Text + ")"
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
lblMsg.Text = "Record is Successfully Inserted"
Else
lblMsg.Text = "Record is not Inserted"
End If
con.Close()
End Sub
Update Records from MySQL Database.
Private Sub UpdateRecords_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim Query As String
Dim con As MySqlConnection = New MySqlConnection("Data
Source=localhost;Database=test;User ID=root;Password=mysql;")
con.Open()
Query = "UPDATE userreg SET UserName ='" + txtUserName.Text + "',"
Query = Query + "Age = " + txtAge.Text
Query = Query + " WHERE idUserReg = " + txtUserRegId.Text
-
8/14/2019 ADA Edit Delete
4/18
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
MsgBox(Query)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
lblMsg.Text = "Record is Successfully Updated"
Else
lblMsg.Text = "Record is not Updated"
End If
con.Close()
End Sub
Delete Records from MySQL Database
Private Sub DeleteRecords_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim Query As String
Dim con As MySqlConnection = New MySqlConnection("Data
Source=localhost;Database=test;User ID=root;Password=mysql;")
con.Open()
Query = "Delete FROM userreg WHERE idUserReg =" +
txtUserRegId.Text
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
MsgBox(Query)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
lblMsg.Text = "Record is Successfully Deleted"
Else
lblMsg.Text = "Record is not Deleted"
End If
con.Close()
End Sub
-
8/14/2019 ADA Edit Delete
5/18
MySQL Database
Here I am creating table in MySQL Data base with Following Fields. The Table Name is
userreg.
idUserReg : int
UserName : Varchar
Age : int
OutPut
Finally We Create Windows Application in VB.Net with MySQL Database. Here Insert,
update, Delete and display Records in grid view.Creating Windows application using
MySQL Database Connection in VB.Net
if you want to know about How to Upload Excel file in ASP.Net Applications. Please
Refer Following Link.
Upload Excel file in ASP.Net Applications
Thanks for spending your valuable time.if you have any doubts or any Suggestion , Let
Me know. I am Happy to update here.
Hope you will enjoy this article and provide your valuable suggestion and feedback.
Thanks
http://www.dotnetspider.com/resources/43050-Excel-file-upload-asp-net-display-grid.aspxhttp://www.dotnetspider.com/resources/43050-Excel-file-upload-asp-net-display-grid.aspxhttp://www.dotnetspider.com/resources/43050-Excel-file-upload-asp-net-display-grid.aspx -
8/14/2019 ADA Edit Delete
6/18
Happy Coding.....
Create Crystal Report from Visual Basic .Net 2008 using Data in DataGridView
Step 1:Prepare data in DataGridView to be placed on CrystalReport
With Me.DataGridView1
.Columns.Add("code", "Code")
.Columns.Add("name", "Name")
.Columns.Add("gender", "Gender")
.Columns.Add("address", "Address")
.EditMode = DataGridViewEditMode.EditProgrammatically
.AllowUserToAddRows = False
End With
-
8/14/2019 ADA Edit Delete
7/18
'add data to datagridview
'example data in 10 rows
For i As Integer = 1 To 0
Me.DataGridView1.Rows.Add()
With Me.DataGridView1.Rows(i)
.Cells("code").Value = Format(i + 1, "0000")
.Cells("name").Value = "Student Name" & i + 1
.Cells("gender").Value = "M"
.Cells("address").Value = "PP"
End With
Next
Step 2:Create DataSet and DataTable for Crystal Report
o Click on Project Menu
o Click on Add New Itemo Choose DataSet (Enter DataSet name)
o Create DataTable in DataSet (Same columns in step 1)
Step 3:Create and Design Crystal Report using Data from DataTable in Step 2
o Click on ProjectMenu
o Click on Add New Item
-
8/14/2019 ADA Edit Delete
8/18
o Choose Reporting -> Crystal Report
o Choose Create As Blank Report
o Right Clickon Database Fieldin Field Explorerof Crystal Report
o Choose Database Expert
o Choose Project Data -> ADO.Net DataSets -> (DataSet and DataTable Created in
Step 2)
o OK
o Drag Each Field in Database Fields into Crystal Report
Step 4:Create Form to View Crystal Report using CrystalReportViewer control
o Create New Form
o Draw CrystalReportViewer Control on Form
o Coding Dim dt As New DataTable
'
With dt
.Columns.Add("code")
.Columns.Add("name")
.Columns.Add("gender")
.Columns.Add("address")
End With
'
For Each dr As DataGridViewRow In Me.DataGridView1.Rows
dt.Rows.Add(dr.Cells("code").Value, dr.Cells("name").Value,
_
dr.Cells("gender").Value,dr.Cells("address").Value)
Next
'
-
8/14/2019 ADA Edit Delete
9/18
Dim rptDoc AsCrystalDecisions.CrystalReports.Engine.ReportDocument
rptDoc = New CrystalReport1
rptDoc.SetDataSource(dt)
'
Form2.CrystalReportViewer1.ReportSource = rptDoc
Form2.ShowDialog()
Form2.Dispose()
-
8/14/2019 ADA Edit Delete
10/18
Crystal Report is an application which can generate various reports from different
data sources, we can create reports, print and preview those report using it, It is
compatible with almost a developing platforms and databases, In this article you
can find useful resources for generating reports from VB.NET with Crystal Report.
We can now see how to create a sample Database and Tables and data. First wehave to create a database. Give the database name as "crystaldb"
Create a DataBase "crystaldb"
In the crystaldb database, let us create three tables OrderMaster, OrderDetails,
Product.
OrderMaster
1. OrderMaster_id
2. OrderMaster_date
3. OrderMaster_customer
4. OrderMaster_createduser
OrderDetails
1. OrderDetails_id
2. OrderDetails_masterid
3. OrderDetails_productid
4. OrderDetails_qty
Product
1. Product_id
2. Product_name3. Product_price
Now that you have a database you can start your first VB.NET Crystal Reports.
All Crystal Reportsprogramming samples in these tutorials are based upon the
following database (crystaldb, the one we created through the previous article).
Open Visual Studio .NET and select a new Visual Basic .NET Project.
-
8/14/2019 ADA Edit Delete
11/18
Create a new Crystal Report for Product table from the above database crystalDB.
The Product Table has three fields (Product_id, Product_name, and
Product_price).
From the main menu in Visual Studio select PROJECT-->Add New Item. Then
Add New Item dialogue will appear and select Crystal Reportsfrom the dialogue
box.
-
8/14/2019 ADA Edit Delete
12/18
Accept the default settings and click OK.
Next step is to select the appropriate connection to your database. Here we are
going to select OLEDB connection for SQL ServerSelect OLE DB ( ADO ) from Create New Connection.
-
8/14/2019 ADA Edit Delete
13/18
-
8/14/2019 ADA Edit Delete
14/18
Next screen is the SQL Server authentication screen. Select your Sql Server
name, enter userid, passwordand select your Database Name. Click next, Thenthe screen shows OLE DB Property values, leave it as it is, and click finish.
Then you will get your Server name under OLEDB Connectionfrom there select
database name (Crystaldb) and click the tables , then you can see all your tables
from your database.
From the tables list select Product table to the right side list.
-
8/14/2019 ADA Edit Delete
15/18
Click Next Button
Select all fields from Product table to the right side list.
-
8/14/2019 ADA Edit Delete
16/18
Click Finish Button. Then you can see the Crystal Reports designer window. You
can arrange the design according your requirements. Your screen looks like the
following picture.
-
8/14/2019 ADA Edit Delete
17/18
Now the designing part is over and the next step is to call the created
Crystal Reports in VB.NET through CrystalReports Viewer control.
Select the default form (Form1.vb) you created in VB.NET and drag a button
and CrystalReportViewercontrol to your form.
Select Form's source code view and put the code on top
Imp orts CrystalDecis ions.CrystalReports.Engine
Put the following source code in the button click event
Imports CrystalDecisions.CrystalReports.Engine
Public Class Form1
Private Sub Button1_Click(ByVal sender As
System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim cryRpt As New ReportDocument
-
8/14/2019 ADA Edit Delete
18/18
cryRpt.Load("PUT CRYSTAL REPORT PATH
HERE\CrystalReport1.rpt")
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
End Class
NOTES:
cryRpt.Load ("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")
The Crystal Reports is in your project location, there you can
see CrystalReport1.rpt. So give the full path name of report here.
After you run the source code you will get the report like this.
Hope this article helps you to create your first Crystal Reports.