is there have any method for connect c++ console application data to the sql data base. i have image processing program using c++ and opencv. now i want save some pictures to the local sql data base. how do that.
What I have tried:
i tried in c#. its working. i want this kind of example
using System;
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.IO;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Diagnostics;
namespace face_detetc_admin
{
public partial class c_pass : Form
{
private SqlConnection DBConn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\aInven\Face_detect\database\db.mdf;Integrated Security=True");
String data;
public c_pass()
{
InitializeComponent();
}
private void updtbtn_Click(object sender, EventArgs e)
{
if (idtxtbx.Text.Length <= 0)
{
MessageBox.Show("User Id not found", "Error...");
}
else if (nwbx.Text != cnfmbx.Text)
{
MessageBox.Show("New password and old password not matched!", "Error...");
}
else if (nwbx.Text.Length <= 0 || cnfmbx.Text.Length <= 0)
{
MessageBox.Show("Some field are missing!", "Error...");
}
else
{
if ((MessageBox.Show("are you sure ?", "Confirmation...", MessageBoxButtons.YesNo) == DialogResult.Yes))
{
try
{
var command = DBConn.CreateCommand();
DBConn.Open();
string strSQL = string.Format("Select * From Log where uname = '{0}'", idtxtbx.Text);
SqlCommand myCommand = new SqlCommand(strSQL, DBConn);
{
myCommand.Parameters.AddWithValue("uname", idtxtbx.Text);
using (SqlDataReader reader = myCommand.ExecuteReader())
{
while (reader.Read())
{
data = reader["pword"].ToString();
}
}
}
if (oldbx.Text == data)
{
using (SqlCommand cmd = new SqlCommand("UPDATE Log SET pword = @pword where uname = @uname", DBConn))
{
cmd.Parameters.AddWithValue("@pword", nwbx.Text);
cmd.Parameters.AddWithValue("@uname", idtxtbx.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Password changed!!!", "Updated");
this.Hide();
}
}
else
{
MessageBox.Show("Not found. Try again!!!", "Error.....");
}
DBConn.Close();
}
catch (SqlException ex)
{
MessageBox.Show("failed" + ex.Message);
}
}
}
}
private void button1_Click(object sender, System.EventArgs e)
{
idtxtbx.Clear();
oldbx.Clear();
nwbx.Clear();
cnfmbx.Clear();
}
private void button3_Click(object sender, System.EventArgs e)
{
if (utxtbx.Text.Length > 0 && ptxtbx.Text.Length > 0 && ptxtbx.Text == ctxtbx.Text)
{
if ((MessageBox.Show("are you sure add this informations?", "Confirmation...", MessageBoxButtons.YesNo) == DialogResult.Yes))
{
try
{
SqlCommand MyCommand = new SqlCommand("INSERT INTO Log" + " VALUES('" + utxtbx.Text + "','" + ptxtbx.Text + "')", DBConn);
DBConn.Open();
MyCommand.ExecuteNonQuery();
DBConn.Close();
MessageBox.Show("Updated!!!");
utxtbx.Clear();
ptxtbx.Clear();
this.Dispose();
}
catch (SqlException ex)
{
MessageBox.Show("failed" + ex.Message);
DBConn.Close();
}
}
}
else
{
MessageBox.Show("Error Input data", "Error...");
}
}
private void button2_Click(object sender, System.EventArgs e)
{
utxtbx.Clear();
ptxtbx.Clear();
ctxtbx.Clear();
}
private void c_pass_Load(object sender, System.EventArgs e)
{
}
}
}