C# ExecuteNonQuery "Connection must be valid and open." - c#

I'm trying to add values into database, but every time I try to add some thing i get an error in the ExecuteNonQuery() with the message "Connection must be valid and open."
And I don't know what to do!!!
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 MySql.Data.MySqlClient;
namespace ClientesClinica
{
public partial class frmCadastro : Form
{
MySqlConnection conect = new MySqlConnection("server = localhost; user id = root; database = clientes; password = '';");
public frmCadastro()
{
InitializeComponent();
}
private void frmCadastro_Load(object sender, EventArgs e)
{
}
private void btnCancela_Click(object sender, EventArgs e)
{
Close();
}
private void btnSalvar_Click(object sender, EventArgs e)
{
int cod;
string nome;
string end;
int tel;
cod = Convert.ToInt16(txtCodigo.Text);
nome = txtNome.Text;
end = txtEndereco.Text;
if (txtNome.Text == "")
{
MessageBox.Show("Favor digitar o nome");
}
if (txtCodigo.Text == "")
{
MessageBox.Show("Favor digitar o código");
}
conect.Close();
MySqlCommand insere = new MySqlCommand();
insere.CommandText = "INSERT INTO cliente(cod, nome, endereco) Values(#cod + ,'#nome', '#end');";
insere.Parameters.AddWithValue("#cod", cod);
insere.Parameters.AddWithValue("#nome", nome);
insere.Parameters.AddWithValue("#end", end);
conect.Open();
insere.ExecuteNonQuery();// THE ERROR IS HERE!!!!
conect.Close();
MessageBox.Show("Salvo");
}

You need to open your connection and supply it to the command as per MSDN: SQLCommand
string queryString = "SELECT OrderID, CustomerID FROM dbo.Orders;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection); //<- See here the connection is passes to the command
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
Or for your usage:
conect.Open(); //<- Open Connection first
MySqlCommand insere = new MySqlCommand();
insere.Connection = conect; //<- Set the Commands connection
insere.CommandText = "INSERT INTO cliente(cod, nome, endereco) Values(#cod + ,'#nome', '#end');";
insere.Parameters.AddWithValue("#cod", cod);
insere.Parameters.AddWithValue("#nome", nome);
insere.Parameters.AddWithValue("#end", end);
insere.ExecuteNonQuery();
conect.Close();

this exception often raise cause of call the ExecuteNonQuery() method before connection opening
MySqlConnection con = new MySqlConnection(connection);
MySqlCommand command = con.CreateCommand();
command.CommandText="insert into stactoverflowtable (id,name) values('1','adil')";//suppose table name is stackoverflowtalbe
try
{
con.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
textBox1.Text = ex.Message;
}

Related

How do I get around my ExecuteScalar returning null?

I am creating a basic registration page using ASP.NET websites and C# and am trying to link the logins to a database I have created in Visual Studio 2017 and am constantly getting the error -
'System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Data.Common.DbCommand.ExecuteScalar(...) returned null.
and cannot understand why, code below any help appreciated.
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ValidationSettings.UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkuser = "SELECT * FROM [Table] WHERE UserName='" + TextBoxUN.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("User already exists, please enter a different username");
}
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "INSERT INTO Table (UserName,Email,Password,Country) values(#Uname ,#email , #password ,#country)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("#Uname" , TextBoxUN.Text);
com.Parameters.AddWithValue("#email" , TextBoxEmail.Text);
com.Parameters.AddWithValue("#password" , TextBoxPass.Text);
com.Parameters.AddWithValue("#country" , DropDownListCountry.SelectedItem.ToString());
com.ExecuteNonQuery();
Response.Redirect("Manager.aspx");
Response.Write("Registration Successful");
conn.Close();
}
catch (Exception ex)
{
Response.Write("Error:" + ex.ToString());
}
}
}```
If you want to check if user exists, there's no need in ExecuteScalar() with value:
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
when user doesn't exist, com.ExecuteScalar() returns null and you have a problem.
Code
private static bool UserExists(string userName) {
if (null == userName)
return false;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString)) {
conn.Open();
//DONE: parametrized query
//DONE: 1 instead of * - we don't want all columns to be returned
string sql =
#"select 1
from [Table]
where UserName = #userName";
using (SqlCommand com = new SqlCommand(sql, conn)) {
com.Parameters.Add("userName", SqlDbType.VarChar).Value = userName;
// user exists if cursor is not empty (we have at least one record)
return com.ExecuteScalar() != null;
}
}
}
protected void Page_Load(object sender, EventArgs e) {
ValidationSettings.UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
if (IsPostBack && UserExists(TextBoxUN.Text))
Response.Write("User already exists, please enter a different username");
}

Update database field SQL in C#

I have tried many things, with no result. My question is, as the title says, how do I update a field in a database using SQL? Since I am a beginner with coding and SQL, I will copy my whole code below, not knowing what information you may need:
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 MySql.Data.MySqlClient;
using HPJFRMS;
namespace HPJFRMS
{
public partial class HomeFRM : Form
{
private string conn;
MySqlConnection connect;
string _naam = "";
Form _Loginfrm;
public HomeFRM(Form logFrom, string _name)
{
_Loginfrm = logFrom;
InitializeComponent();
lbWelkom.Text = "welkom " + _name;
_naam = _name;
}
private void HomeFRM_Load(object sender, EventArgs e)
{
tmCheck.Enabled = true;
}
private bool Todo_ophalen()
{
db_connection();
MySqlCommand cmdRead = new MySqlCommand();
cmdRead.CommandText = "SELECT `todo` FROM `user` WHERE `username` LIKE '" + _naam + "'";
cmdRead.Connection = connect;
MySqlDataReader tdOphalen = cmdRead.ExecuteReader();
if (tdOphalen.Read())
{
tbTodo.Text = tdOphalen.GetString(0);
connect.Close();
return true;
}
else
{
connect.Close();
return false;
}
}
private void db_connection()
{
try
{
conn = "Server=127.0.0.1;Database=users;Uid=root;Pwd=;";
connect = new MySqlConnection(conn);
connect.Open();
}
catch (MySqlException e)
{
throw;
}
finally
{
lbStatus.ForeColor = Color.Red;
}
}
private void btBewerk_Click(object sender, EventArgs e)
{
if (btBewerk.Text == "Bewerken")
{
tbTodo.ReadOnly = false;
btBewerk.Text = "Opslaan";
tmCheck.Enabled = false;
}
else
{
/* HERE COMES THE "UPDATE" CODE */
}
}
private void tmCheck_Tick(object sender, EventArgs e)
{
try
{
bool T = Todo_ophalen();
if (T)
{
lbStatus.ForeColor = Color.Green;
lbStatus.Text = "Online";
}
}
catch
{
lbStatus.ForeColor = Color.Red;
lbStatus.Text = "Offline";
}
}
}
}
There are different methods, you can use any of these.
Method 1: using simple SQL query
public void Update(Int UserId,String UserName )
{
SqlConnection con = new SqlConnection("Your Connection String");
con.Open();
string str = " UPDATE [dbo].[User] SET [UserName] = "+UserName +" WHERE [UserId] ="+ UserId+"";
SqlCommand cmd = new SqlCommand(str , con);
cmd.ExecuteNonQuery();
con.Close();
}
Method 2: using a stored procedure
First execute your stored procedure in database.
Example
CREATE PROCEDURE [dbo].[UpdateUser]
#UserId int,
#UserName varchar(25)
AS
BEGIN
UPDATE [dbo].[User]
SET [UserName] = #UserName
WHERE [UserId] = #UserId
END
public void Update(Int UserId,String UserName )
{
SqlConnection con = new SqlConnection("Your Connection String");
con.Open();
SqlCommand cmd = new SqlCommand("UpdateUser", con); //UpdateUser is the name of stored procedure you created
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("UserName ", UserName );
cmd.Parameters.AddWithValue("UserId", UserId);
cmd.ExecuteNonQuery();
con.Close();
}
Here is a sample method for an update:
public void UpdateUser(User userToUpdate)
{
try
{
string sqlStatement = #"UPDATE USERS " +
"SET DisplayName = #DisplayName, Username = #Username" +
"WHERE Id = #Id";
using (SqlConnectionconn = new SqlConnection("connection string here"))
using (SqlCommand cmd = new SqlCommand(sqlStatement, conn))
{
cmd.Parameters.Add(new SqlParameter("#Id", userToUpdate.Id));
cmd.Parameters.Add(new SqlParameter("#DisplayName", userToUpdate.DisplayName));
cmd.Parameters.Add(new SqlParameter("#UserName", userToUpdate.UserName));
cmd.ExecuteNonQuery();
}
}
catch (DbException ex)
{
throw ExceptionHandler.CreateSystemException(ex, ErrorStrings.DATABASE_ERROR);
}
}
This should get you started but you really need to read up on this subject as explaining the correct practices would be too long for an answer here.
this is maybe you need
MySqlConnection con = new MySqlConnection(conStr);
try
{
con.Open();
MySqlCommand cmd = new MySqlCommand(con);
cmd.CommandText = "UPDATE table_name SET field_name_1 = ?param1, field_name_2 = ?param2 WHERE id = ?id";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("?param1", value1);
cmd.Parameters.AddWithValue("?param2", value2);
cmd.Parameters.AddWithValue("?id", value3);
cmd.ExecuteNonQuery();
}
catch (MySqlException ee)
{
MessageBox.Show(ee.Message);
}
finally
{
con.Close();
con.Dispose();
}

What is the correct syntax for establishing an SQL connection and creating SQL Commands with VS2012?

I'm not really sure where the SqlConnection, SqlCommand and the Open()/Close() goes. I want to use just the single variable cmd throughout the program, hence not using the SqlCommand cmd = new SqlCommand('SELCT * FROM blabla); format.
EDIT: My code below results to the textbox having the text "System.Data.SqlClient.SqlCommand" when i click the button.
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;
using System.Data.SqlTypes;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(#"Data Source=EDIOTH\SQLEXPRESS;
Initial Catalog=Try; Integrated Security=SSPI");
SqlCommand cmd = new SqlCommand();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
cmd.CommandText = "SELECT Pnt_Lname FROM PATIENT WHERE Pnt_ID = 1;";
txtBox1.Text = cmd.ToString();
con.Close();
}
}
}
you can create constant string to hold the connection string and then you can do as below in your button1_Click
you don't need to call the close method of sql connection when you use using block as below
using(SqlConnection con = new SqlConnection(connectionString))
using(SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "SELECT Pnt_Lname FROM PATIENT WHERE Pnt_ID = 1";
con.Open();
txtBox1.Text =cmd.ExecuteScalar() as string;
}
And also if you need to read Pnt_Lname from database you better use ExecuteScalar method
You can use this structure. Use using to properly close and dispose of SqlConnection.
Also, you can define the connection string in your config file and use it from there.
using (SqlConnection conn = new SqlConnection(#"Data Source=EDIOTH\SQLEXPRESS;
Initial Catalog=Try; Integrated Security=SSPI"))
{
conn.Open();
SqlCommand command = conn.CreateCommand();
command.CommandText = "SELECT Pnt_Lname FROM PATIENT WHERE Pnt_ID = 1";
txtBox1.Text = (String)command.ExecuteScalar();
}
In case this would be of help to anyone, this is the answer to my question:
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 Book
{
public partial class frmBook : Form
{
SqlConnection con =
new SqlConnection(#"Data Source=EDIOTH\SQLEXPRESS;
Initial Catalog=XXDB; Integrated Security=SSPI");
SqlCommand cmd;
public frmBook()
{
InitializeComponent();
}
private void frmBook_Load(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("SELECT min(Book_ID) FROM Book;",con);
txtID.Text = cmd.ExecuteScalar().ToString();
cmd = new SqlCommand("SELECT title FROM Book WHERE Book_ID = '"
+ txtID.Text + "'", con);
txtTitle.Text = cmd.ExecuteScalar().ToString();
con.Close();
btnSave.Enabled = false;
}
private void btnNext_Click(object sender, EventArgs e)
{
int count = int.Parse(txtID.Text) + 1;
con.Open();
cmd = new SqlCommand("SELECT title FROM Book WHERE Book_ID = '"
+ count.ToString() +"'", con);
txtTitle.Text = cmd.ExecuteScalar().ToString();
txtID.Text = count.ToString();
con.Close();
}
private void btnNew_Click(object sender, EventArgs e)
{
txtID.Text = "";
txtTitle.Text = "";
txtAuthor.Text = "";
btnNew.Enabled = false;
btnSave.Enabled = true;
}
private void btnSave_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("INSERT INTO Book (Book_ID, Title, Author) " +
"VALUES ('"+ txtID.Text +
"','"+ txtTitle.Text +
"','"+ txtAuthor.Text +"');", con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data saved!");
btnSave.Enabled = false;
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

Using VS2010 with SqlClient and SQL Server 2012

I'm having a little problem inserting data from my application into my database. I do not get any errors while connecting or trying to insert into the database but data just doesn't get inserted. I use Visual Studio 2010 with C# and SqlClient and SQL Server 2012 Management Studio.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
<summary>
Summary description for Sources
</summary>
public class Sources
{
private string conString;
public int mSourceID;
public string mSourceName;
public int mActive;
public Sources()
{
conString = WebConfigurationManager.ConnectionStrings["dbconstring"].ConnectionString;
mSourceID = 0;
mSourceName = "";
mActive = 0;
}
public void insertData()
{
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
try
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Sources(SourceID, SourceName, Active) VALUES(#SourceID, #SourceName, #Active)", con))
{
cmd.Parameters.Add(new SqlParameter("SourceID", mSourceID));
cmd.Parameters.Add(new SqlParameter("SourceName", mSourceName));
cmd.Parameters.Add(new SqlParameter("Active", mActive));
}
}
catch (Exception Ex)
{
Console.WriteLine("Unable To Save Data. Error - " + Ex.Message);
}
}
}
}
And here is the button click event:
protected void btnOk_Click(object sender, ImageClickEventArgs e)
{
Sources src = new Sources();
src.mSourceID = 1;
src.mSourceName = "aboa";
src.mActive = 0;
src.insertData();
}
I've checked the debugger and do not get any errors thrown when I click the button, but when I check my table in my database it remains empty.
You need to execute your query using ExecuteNonQuery .check the below code.
public void insertData()
{
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
try
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Sources(SourceID, SourceName, Active) VALUES(#SourceID, #SourceName, #Active)", con))
{
cmd.Parameters.Add(new SqlParameter("SourceID", mSourceID));
cmd.Parameters.Add(new SqlParameter("SourceName", mSourceName));
cmd.Parameters.Add(new SqlParameter("Active", mActive));
cmd.ExecuteNonQuery();
}
}
catch (Exception Ex)
{
Console.WriteLine("Unable To Save Data. Error - " + Ex.Message);
}
}
}
You need to executenonquery because you are not retourning any data you are only inserting
and u also need the finally block to ensure that even if there is an exception the connection will be closed
public void insertData()
{
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
try
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Sources(SourceID, SourceName, Active) VALUES(#SourceID, #SourceName, #Active)", con))
{
cmd.Parameters.Add(new SqlParameter("SourceID", mSourceID));
cmd.Parameters.Add(new SqlParameter("SourceName", mSourceName));
cmd.Parameters.Add(new SqlParameter("Active", mActive));
cmd.ExecuteNonQuery();
}
}
catch (Exception Ex)
{
Console.WriteLine("Unable To Save Data. Error - " + Ex.Message);
}
finally
{
con.Close();
}
}
}

problem getting my data from access 2003 db into c# (dbReader.GetString error)

[got a bit further so its updated]
Hello There, i really hope you are able to help me!
Now the first part of my code does work, and I do get my report numbers out in my combobox, and i'm able to write that number to a lbl. now I need to take that number and get the rest of my data from my Access 2003 database, and drop them in a string (my output). ( I dont really want all the data loaded into my mem when i open the program, so i belive only getting the [Rapport nr] until i choose one, where I will load the data into the string and save it there for now) :)
my problem is that this wont work!
output = dbReader.GetString(dbReader.GetOrdinal("Dato")).ToString();
OBS: my error is now that it says i dont have any data in my rows or coloums
my code is as follows:
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.Collections;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private string aktuelRapportNR = "";
string output = "";
private string connectionName = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=semcqdjh-access 2007.mdb;"
+ "Jet OLEDB:Database Password=;";
public Form1()
{
InitializeComponent();
#region Indlæsning af combobox, med rapport numre
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;
Myconnection = new OleDbConnection(connectionName);
Myconnection.Open();
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT [Rapport nr] FROM AVR";
dbReader = cmd.ExecuteReader();
int rapportNR;
while (dbReader.Read())
{
rapportNR = (int)dbReader.GetInt32(dbReader.GetOrdinal("Rapport nr"));
comboBox1.Items.Add(rapportNR);
}
dbReader.Close();
Myconnection.Close();
#endregion
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
aktuelRapportNR = comboBox1.SelectedItem.ToString();
lblAktuelRapportNR.Text = aktuelRapportNR;
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;
Myconnection = new OleDbConnection(connectionName);
Myconnection.Open();
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT [Dato] FROM AVR WHERE [Rapport nr] =" + aktuelRapportNR;
dbReader = cmd.ExecuteReader();
try
{
output = dbReader.GetString(dbReader.GetOrdinal("Dato")).ToString();
}
catch (Exception)
{
output = "fejl eller tom";
}
dbReader.Close();
Myconnection.Close();
label1.Text = output;
}
private void btnExport_Click(object sender, EventArgs e)
{
}
}
}
i figured this out :D after a break i went back to this and tried to see if there where enother method i could use and there was :P i figured by the error that it was properly something about the types so insted of taking one out and trying to work around that i took the hole row out and placed it in a object array :P by using GetValues in the dbReader i got it to work, so i can now move on :D for those who might be interested! here is my code :P its not pretty but it works :P i allso took in som try catch just to make sure i check for errors and getting a friendly respons on that :)
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.Collections;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private string aktuelRapportNR = "";
string output;
private string connectionName = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=semcqdjh-access 2007.mdb;"
+ "Jet OLEDB:Database Password=;";
public Form1()
{
InitializeComponent();
#region Indlæsning af combobox, med rapport numre
try
{
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;
Myconnection = new OleDbConnection(connectionName);
Myconnection.Open();
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT [Rapport nr] FROM AVR";
dbReader = cmd.ExecuteReader();
int rapportNR;
while (dbReader.Read())
{
rapportNR = (int)dbReader.GetInt32(dbReader.GetOrdinal("Rapport nr"));
comboBox1.Items.Add(rapportNR);
}
dbReader.Close();
Myconnection.Close();
txtStatus.Text = "Indlæsning Fuldført! Vælg venligst en rapport";
}
catch (Exception)
{
txtStatus.Text = "Indlæsning Fejlet!";
}
#endregion
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
aktuelRapportNR = comboBox1.SelectedItem.ToString();
lblAktuelRapportNR.Text = aktuelRapportNR;
txtStatus.Text = "Du har valgt rapport nr.: " + aktuelRapportNR + "! Klik på export";
}
private void btnExport_Click(object sender, EventArgs e)
{
try
{
OleDbConnection Myconnection = null;
OleDbDataReader dbReader = null;
Myconnection = new OleDbConnection(connectionName);
Myconnection.Open();
OleDbCommand cmd = Myconnection.CreateCommand();
cmd.CommandText = "SELECT * FROM AVR WHERE [Rapport nr] =" + aktuelRapportNR;
dbReader = cmd.ExecuteReader();
object[] liste = new object[dbReader.FieldCount];
if (dbReader.Read() == true)
{
int NumberOfColums = dbReader.GetValues(liste);
for (int i = 0; i < NumberOfColums; i++)
{
output += "|" + liste[i].ToString();
}
}
dbReader.Close();
Myconnection.Close();
txtStatus.Text = "Export Lykkes! Luk programmet!";
}
catch (Exception)
{
txtStatus.Text = "Export Fejlet!";
}
}
}
}

Categories

Resources