3
Reply

Instance failure...???

Mfwamba Tshimanga

Mfwamba Tshimanga

Jun 25 2014 11:08 AM
747
Hi!
 
I wrote this code but when I click on my save button. Its stack and show message that saying: instance failure. I do check the database path its sound correct. Its showing the but on conn.open;
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ElSoft_FactuStocks
{
public partial class Facturacao : Form
{
public Facturacao()
{
InitializeComponent();
bindCombo();
}
SqlConnection conn;
SqlCommand comm;
SqlDataReader dreader;
string connstr = @"Data Source=localhost\\sqlexpress;Initial Catalog=lunaoffice;Integrated Security=True";
 
private void btnGravar_Facturacao_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connstr);
conn.Open();// here
comm = new SqlCommand("insert into fact values(" + symb.Text + ",'" + nomeClienteFactu.Text + ",'" + artigoFactu.Text + "'," + leituraCodFactu.Text +
 ",'" + quantidadeFactu.Text + ",'" + precosaidaFactu.Text + ",'" + totalFactu.Text + ",'" + descontoFactu.Text + ",'" + utilizadores.Text + "')", conn);
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Saved...");
}
catch (Exception)
{
MessageBox.Show("Not Saved");
}
finally
{
conn.Close();
}
 
 

Answers (3)