Create a Application to connect access database with C# - Complete Course
Programming in VB. net: Video about pagination in datagridview
Imports System.Data.SqlClient
Public Class Form5
Dim pagerows As Integer
Dim conn As New SqlConnection("Data Source=.;Initial catalog=sports;Integrated Security=True")
Private Sub count_rows()
Dim cmd As New SqlCommand("Select Count(*) From table1", conn)
conn.Open()
Dim count1 As Integer
count1 = Convert.ToString(cmd.ExecuteScalar)
pagerows = Math.Ceiling(count1 / 10)
Label3.Text = pagerows
conn.Close()
End Sub
Private Sub Form5_Load(sender As Object, e As EventArgs) Handles Me.Load
count_rows()
End Sub
Private Sub load_data()
Dim f1 As Integer = Label1.Text * 10 - 10 + 1
Dim t1 As Integer = Label1.Text * 10
Dim cmd As New SqlCommand("Select * From(Select Row_Number() Over (Order By sport) As rownumber,id,name,age,sport,points From table1)tablerow Where rownumber Between " & f1 & "And " & t1 & "", conn)
Dim da As New SqlDataAdapter
da.SelectCommand = cmd
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = 1
load_data()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Label1.Text < pagerows Then
Label1.Text = Label1.Text + 1
load_data()
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If Label1.Text > 1 Then
Label1.Text = Label1.Text - 1
load_data()
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Label1.Text = pagerows
load_data()
End Sub
End Class
insert update delete search and print in sql server databse using C# [with Source code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Insert_update_delete_search_and_print_in_sql
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlConnection conn = new SqlConnection("Data source=.;initial catalog=database3;integrated security=true");
private void Form2_Load(object sender, EventArgs e)
{
bind_data();
}
private void bind_data()
{
SqlCommand cmd1 = new SqlCommand("Select id,fname As firstname,lname As Lastname,sum from Table1", conn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd1;
DataTable dt = new DataTable();
dt.Clear();
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Bold);
dataGridView1.DefaultCellStyle.Font = new Font("arial", 12);
}
private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmd2 = new SqlCommand("Insert into Table1(id,fname,lname,sum)Values(@id,@firstname,@lastname,@sum)", conn);
cmd2.Parameters.AddWithValue("id", textBox1.Text);
cmd2.Parameters.AddWithValue("firstname", textBox2.Text);
cmd2.Parameters.AddWithValue("lastname", textBox3.Text);
cmd2.Parameters.AddWithValue("sum", textBox4.Text);
conn.Open();
cmd2.ExecuteNonQuery();
conn.Close();
bind_data();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int index;
index = e.RowIndex;
DataGridViewRow selectedrow = dataGridView1.Rows[index];
textBox1.Text = selectedrow.Cells[0].Value.ToString();
textBox2.Text = selectedrow.Cells[1].Value.ToString();
textBox3.Text = selectedrow.Cells[2].Value.ToString();
textBox4.Text = selectedrow.Cells[3].Value.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
SqlCommand cmd3 = new SqlCommand("Update Table1 Set fname=@firstname,lname=@lastname,sum=@sum where id=@id", conn);
cmd3.Parameters.AddWithValue("firstname", textBox2.Text);
cmd3.Parameters.AddWithValue("lastname", textBox3.Text);
cmd3.Parameters.AddWithValue("sum", textBox4.Text);
cmd3.Parameters.AddWithValue("id", textBox1.Text);
conn.Open();
cmd3.ExecuteNonQuery();
conn.Close();
bind_data();
}
private void button4_Click(object sender, EventArgs e)
{
SqlCommand cmd4 = new SqlCommand("Delete from Table1 where id=@id", conn);
cmd4.Parameters.AddWithValue("id", textBox1.Text);
conn.Open();
cmd4.ExecuteNonQuery();
conn.Close();
bind_data();
}
private void button5_Click(object sender, EventArgs e)
{
SqlCommand cmd1 = new SqlCommand("Select id,fname As firstname,lname As Lastname,sum from Table1 where fname Like @firstname+'%'", conn);
cmd1.Parameters.AddWithValue("firstname", textBox5.Text);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd1;
DataTable dt = new DataTable();
dt.Clear();
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 12, FontStyle.Bold);
dataGridView1.DefaultCellStyle.Font = new Font("arial", 12);
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Bitmap imagebmp = new Bitmap(dataGridView1.Width, dataGridView1.Height);
dataGridView1.DrawToBitmap(imagebmp, new Rectangle(0, 0, dataGridView1.Width, dataGridView1.Height));
e.Graphics.DrawImage(imagebmp, 120, 20);
}
private void button6_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.PrintPreviewControl.Zoom = 1;
printPreviewDialog1.ShowDialog();
}
}
}
Step by step learn (HTML,PHP and mysql database) with login and logout page with session in PHP
Step by step learn (HTML,PHP and mysql database) with login and logout page with session in PHP Contents: Create a new folder website 00:00 Save as a webpage in folder website login.php 00:29 HTML !DOCTYPE Declaration is an "information" to the browser about what document type to expect. 01:04 The html tag represents the root of an HTML document,and close by 01:13 The header element represents a container for introductory content or a set of navigational links. 01:18 meta charset="UTF-8" 01:23 you are telling your browser to use the UTF-8 character encoding, which is a method of converting your typed characters into machine-readable code. The title tag defines the title of the document 01:39 body contains all the contents of an HTML document. 02:06 The div tag defines a division or a section in an HTML document. 02:56 The h1 tag is used to define HTML heading. 03:13 Add styles to Div "aa" 03:43 Make div in the Center 05:13 Make the text in the center 05:13 The form tag is used to create an HTML form for user input. 06:25 The br tag inserts a single line break.08:04 Add a short hint that describes the expected value of an input field 09:37 Make input fields must be filled out before submitting the form 10:28 OPen XAMPP to create mysql database 11:14 Create database in phpmyadmin 11:59 Create table 12:34 Insert User 13:50 Connect php with database 14:24 Check connection 15:44 Add code php in login page 16:54 Call connect_database file by require 17:14 Start Session 17:41 check if the input username is filled or not null. 17:54 Removes backslashes 18:21 Escapes a string for use in SQL Statements 31:37 check if username exists in mysql database or no 20:05 mysqli_num_rows Returns the number of rows in a recordest 22:03 Store Session Username 22:43 Redirect to index.php Page 23:07 Error message 23:36 Check if session username exists 26:27 Create index page 27:46 Add hyperlink 29:39 Create logout page with destroy or remove session username 29:53 #programming_for_everybody Tags: How to connect HTML register form to MySQL database with PHP Login PHP Admin and user login in PHP Administrator login php Registration form in PHP code with validation PHP admin login
Visual Basic.net: how to calculate third column in a datagridview as product of two other columns
Public Class Form8
Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim table As New DataTable("table")
table.Columns.Add("ID", Type.GetType("System.Int32"))
table.Columns.Add("Name", Type.GetType("System.String"))
table.Columns.Add("Arabic", Type.GetType("System.Double"))
table.Columns.Add("English", Type.GetType("System.Double"))
table.Columns.Add("Sum", Type.GetType("System.Double"))
DataGridView1.DataSource = table
End Sub
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
For i As Integer = 0 To DataGridView1.Rows.Count - 1
Dim a1 As Double = DataGridView1.Rows(i).Cells(2).Value
Dim b1 As Double = DataGridView1.Rows(i).Cells(3).Value
Dim c1 As Double = a1 + b1
DataGridView1.Rows(i).Cells(4).Value = c1
Next
End Sub
Private Sub DataGridView1_DefaultValuesNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles DataGridView1.DefaultValuesNeeded
e.Row.Cells("Arabic").Value = "0"
e.Row.Cells("English").Value = "0"
e.Row.Cells("Sum").Value = "0"
End Sub
Visual Basic.net: retrieve values from database in row datagridview based on cell in Same row
Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Right Then
For i As Integer = 0 To DataGridView1.Rows.Count - 1
Dim constring1 As String = "data source=.;initial catalog=users;integrated security=true"
Dim query1 As String = " select id,name,country from table2 where id='" & DataGridView1.Rows(i).Cells(0).Value & "'"
Dim cn1 As SqlConnection = New SqlConnection(constring1)
Dim cmd1 As SqlCommand = New SqlCommand(query1, cn1)
cn1.Open()
If True Then
Using read1 As SqlDataReader = cmd1.ExecuteReader()
While read1.Read()
DataGridView1.Rows(i).Cells(1).Value = (read1("name"))
DataGridView1.Rows(i).Cells(2).Value = (read1("country"))
End While
End Using
End If
cn1.Close()
Next
End If
End Sub
VB.net: filter dates from access database between two datetimepickers and display in datagridview with source code
Imports System.Data.OleDb
Public Class Form4
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\dates.accdb")
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
d1.Format = DateTimePickerFormat.Custom
d1.CustomFormat = "MM/dd/yyyy"
d2.Format = DateTimePickerFormat.Custom
d2.CustomFormat = "MM/dd/yyyy"
DataGridView1.BackgroundColor = System.Drawing.SystemColors.Control
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim cmd1 As New OleDbCommand(" select id,date1,username from table1", conn)
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
da.SelectCommand = cmd1
dt.Clear()
da.Fill(dt)
DataGridView1.DataSource = dt
DataGridView1.Columns(1).DefaultCellStyle.Format = "dd/MM/yyyy"
DataGridView1.Columns(0).HeaderText = "ID"
DataGridView1.Columns(1).HeaderText = "Start date"
DataGridView1.Columns(2).HeaderText = "Username"
DataGridView1.EnableHeadersVisualStyles = False
With DataGridView1.ColumnHeadersDefaultCellStyle
.Font = New Font("arial", 12, FontStyle.Italic)
.BackColor = Color.Black
.ForeColor = Color.White
End With
DataGridView1.Columns(0).DefaultCellStyle.Font = New Font("tahoma", 10, FontStyle.Bold)
DataGridView1.Columns(1).DefaultCellStyle.Font = New Font("tahoma", 10, FontStyle.Italic)
DataGridView1.Columns(2).DefaultCellStyle.Font = New Font("tahoma", 10, FontStyle.Underline)
DataGridView1.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.TopCenter
DataGridView1.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.TopCenter
DataGridView1.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.TopCenter
DataGridView1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
DataGridView1.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
DataGridView1.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
DataGridView1.Columns(0).DefaultCellStyle.BackColor = Color.Yellow
DataGridView1.Columns(1).DefaultCellStyle.BackColor = Color.Brown
DataGridView1.Columns(2).DefaultCellStyle.BackColor = Color.Green
DataGridView1.Rows(0).Cells(0).Selected = False
DataGridView1.Rows(2).Cells(1).Selected = False
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim dtdate1 As DateTime = DateTime.Parse(d1.Text)
Dim dtdate2 As DateTime = DateTime.Parse(d2.Text)
Dim cmd1 As OleDbCommand = New OleDbCommand("select id,date1,username from table1 where date1 between #" &
dtdate1.ToString("MM/dd/yyyy") & "# and #" &
dtdate2.ToString("MM/dd/yyyy") & "# order by date1 desc", conn)
Dim da As New OleDbDataAdapter
da.SelectCommand = cmd1
Dim dt As New DataTable
dt.Clear()
da.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
End Sub
End Class