Skip to main content

Posts

Showing posts with the label sqlcommand

Example of code of c sharp with SQL Server connectivity

using System; using System.Data; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Drawing; namespace DatabaseExp { public partial class DatabaseExp : Form { SqlConnection conn; SqlDataAdapter adaptr; SqlCommand cmd; DataTable tbl; static int count = 0, current = 0; static int check = 0; public DatabaseExp() { InitializeComponent(); } private void DatabaseExp_Load(object sender, EventArgs e) { string connectionString = null; adaptr = new SqlDataAdapter(); tbl = new DataTable(); connectionString = "Data Source=127.0.0.1;Initial Catalog=Abdul;User ID=sa;Password=allah"; conn = new SqlConnection(connectionString); try { conn.Open(); MessageBox.Show("Connection Open !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //conn.Close(); } catch (Exception ex) { Message

Create table runtime using c sharp code

Create table runtime using c sharp code try { if (RadioButton1.Checked == true) { string first = TextBox1.Text.ToString(); string last = TextBox3.Text.ToString(); string user = TextBox4.Text.ToString(); string ps = TextBox6.Text.ToString(); string quest = DropDownList1.Text.ToString(); string answ = TextBox7.Text.ToString(); string source = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\dfd.mdf;Integrated Security=True; User Instance=True"; SqlConnection conn = new SqlConnection(source); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO users(fname, lname, uid, pswd, ques, ans) VALUES ('" + first + "', '" + last + "', '" + user + "', '" + ps + "', '" + quest + "', '" + answ + "')", conn); int i = cmd.ExecuteNonQuery(); String sql = "CREATE TABLE " + user + "" +"(Stu

Example of SQL script injection

SQL script injection collectionstring sql= “SELECT COUNT(EmailName) FROM Users WHERE “ + “EmailName=@Username AND Password=@Password”; sqlCommandcmd= new SqlCommand(sql, connection); cmd.Parameters.Add(“@Username”, txtUsername); cmd.Parameters.Add(“@Password”, txtPassword); connection.Open(); intcount = (int)command.ExecuteScalar(); connection.Close()