My Name Is Salman Masood , I am Computer Science &Amp; Maths Graduate from University of Karachi, Pakistan , Teaching Is My Passion and My Aim Is to Deliver All My Knowledge among Those Students Who Can'T Afford Tutors or Expensive Institute Fees. I Will Be Keep Sharing My All Knowledge and Information with You .... Remember Me in Your Prayers !
Thursday, 18 January 2018
Learn C language Part -40 SQL ORACLE DATABASE STRUCTURE IN C LANGUAGE
#include <stdio.h>
#include <conio.h>
#include <string.h>
struct employee
{
int id ;
char name[50];
float salary;
char department[50] ;
};
main()
{
int i;
struct employee e1[5];
e1[0].id=101;
strcpy(e1[0].name,"Ali");
e1[0].salary=50000;
strcpy(e1[0].department,"HR");
//2ND RECORD..........................
e1[1].id=102;
strcpy(e1[1].name,"BILAL");
e1[1].salary=60000;
strcpy(e1[1].department,"IT");
//3rd RECORD..........................
e1[2].id=103;
strcpy(e1[2].name,"Daniyal");
e1[2].salary=40000;
strcpy(e1[2].department,"Marketing");
//3rd RECORD..........................
e1[3].id=104;
strcpy(e1[3].name,"Eraj");
e1[3].salary=30000;
strcpy(e1[3].department,"Admin");
//4th RECORD..........................
e1[4].id=105;
strcpy(e1[4].name,"faisal");
e1[4].salary=20000;
strcpy(e1[4].department,"Admin");
l1:
printf("\nID\tName\t\tSalary\t\tDepatment\t\n\n");
for(i=0;i<5;i++)
{
printf("\n-----------------------------------------------------------\n");
printf("%d\t%s\t\t%.2f\t\t%s\t",e1[i].id,e1[i].name,e1[i].salary,e1[i].department);
printf("\n");
}
printf("\n-----------------------------------------------------------\n");
printf("Enter the id: ");
int n;
scanf("%d",&n);
for(i=0;i<5;i++)
{
if(e1[i].id==n)
{
printf("\nID\tName\t\tSalary\t\tDepatment\t\n\n");
printf("\n-----------------------------------------------------------\n");
printf("%d\t%s\t\t%.2f\t\t%s\t",e1[i].id,e1[i].name,e1[i].salary,e1[i].department);
printf("\n");
n=-1;
break;
}
}
if(n!=-1)
{
printf("\n No Records found......");
}
printf("\nDo you want to continue......{y/n}\n");
char c;
scanf("%c",&c);
c=getchar();
if(c=='y')
{
printf("\n\n");
goto l1;
}
}
Learn C language Part 39 Structures in C language
#include <stdio.h>
#include <conio.h>
#include <string.h>
struct employee
{
int id ;
char name[50];
float salary;
char department[50] ;
};
main()
{
struct employee e1;
struct employee e2;
e1.id=101;
strcpy(e1.name,"Ali");
e1.salary=50000;
strcpy(e1.department,"HR");
//2ND RECORD..........................
e2.id=102;
strcpy(e2.name,"BILAL");
e2.salary=60000;
strcpy(e2.department,"IT");
//PRINTING........................
printf("Employee ID: %d\nName of Employee : %s \nSalary:%f\nDepatment: %s",e1.id,e1.name,e1.salary,e1.department);
printf("Employee ID: %d\nName of Employee : %s \nSalary:%f\nDepatment: %s",e2.id,e2.name,e2.salary,e2.department);
}
part 27-SQL injection and prevention In asp.net
backend code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApplication17
{
public partial class WebForm1 : System.Web.UI.Page
{
string cs = ConfigurationManager.ConnectionStrings["test"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string q = "select * from tblProductInventory";
displayrecord(q);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(cs);
try
{
SqlCommand cmd = new SqlCommand("spsqlinjectionofproduct", con);
cmd.Parameters.AddWithValue("@productname", TextBox1.Text);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataSource = rdr;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write("ERROR IS FOUND " + ex);
}
finally
{
con.Close();
}
}
public void displayrecord(string q)
{
SqlConnection con = new SqlConnection(cs);
try
{
SqlCommand cmd = new SqlCommand(q, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataSource = rdr;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write("ERROR IS FOUND " + ex);
}
finally
{
con.Close();
}
}
}
}
Front end code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication17.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="268px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Height="441px" Width="861px">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<h1>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</h1>
</div>
</form>
</body>
</html>
web.config code:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<connectionStrings>
<add name="test" connectionString="Data Source=faculty-35;Initial Catalog=ADODOTNET_LEARNING;Persist Security Info=True;User ID=sa;Password=aptech" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
part 27-SQL injection and prevention In asp.net
backend code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApplication17
{
public partial class WebForm1 : System.Web.UI.Page
{
string cs = ConfigurationManager.ConnectionStrings["test"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string q = "select * from tblProductInventory";
displayrecord(q);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(cs);
try
{
SqlCommand cmd = new SqlCommand("spsqlinjectionofproduct", con);
cmd.Parameters.AddWithValue("@productname", TextBox1.Text);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataSource = rdr;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write("ERROR IS FOUND " + ex);
}
finally
{
con.Close();
}
}
public void displayrecord(string q)
{
SqlConnection con = new SqlConnection(cs);
try
{
SqlCommand cmd = new SqlCommand(q, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataSource = rdr;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write("ERROR IS FOUND " + ex);
}
finally
{
con.Close();
}
}
}
}
Front end code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication17.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="268px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Height="441px" Width="861px">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<h1>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</h1>
</div>
</form>
</body>
</html>
web.config code:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<connectionStrings>
<add name="test" connectionString="Data Source=faculty-35;Initial Catalog=ADODOTNET_LEARNING;Persist Security Info=True;User ID=sa;Password=aptech" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
Subscribe to:
Posts (Atom)
Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC
Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...
-
Load event: pictureBox3.Image = Image .FromFile( @"C:\Users\salman\Documents\Visual Studio 2013\Projects\WindowsFormsApplication3\W...