Skip to content

Instantly share code, notes, and snippets.

@reuniware
Created March 12, 2021 13:50
Show Gist options
  • Save reuniware/a515f2279caa821041ddfeff01840e75 to your computer and use it in GitHub Desktop.
Save reuniware/a515f2279caa821041ddfeff01840e75 to your computer and use it in GitHub Desktop.
Windev 26, C#, SQL Server Insert
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public static bool InsertCSharp(String sql)
{
try {
string connectionString;
SqlConnection cnn;
connectionString = @"Data Source=MYSQLSERVER;Initial Catalog=;User ID=username;Password=password123";
cnn = new SqlConnection(connectionString);
cnn.Open();
//MessageBox.Show("Connection Open !");
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand command = new SqlCommand(sql, cnn);
adapter.InsertCommand = command;
adapter.InsertCommand.ExecuteNonQuery();
//command.Dispose();
//cnn.Close();
return true;
}
catch(Exception ex)
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment