[c#] How do I to insert data into an SQL table using C# as well as implement an upload function?

Below is the code I am working with to try to insert data into my 'ArticlesTBL' table. I also want to upload an image file to my computer.

I am getting an error reading: Incorrect syntax near 'UploadedUserFiles'.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class _CopyOfSubmitArticle : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void uploadbutton_Click(object sender, EventArgs e)
{
    string UpPath = Server.MapPath("~/UploadedUserFiles");

        int imgSize = FileUpload1.PostedFile.ContentLength;
        string imgName = FileUpload1.FileName;
        string imgPath = "UploadedUserFiles/" + imgName;

        if (FileUpload1.PostedFile.ContentLength > 1000000)
        {
            Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big')", true);
        }

        else
        {
            FileUpload1.SaveAs(Server.MapPath(imgPath));
            myinfo.Text = "file" + imgPath + "uploaded.";
        }



    String connectionString = WebConfigurationManager.ConnectionStrings["ConnectAntiFrack"].ConnectionString;

    SqlConnection myConnection = new SqlConnection(connectionString);

    myConnection.Open();

    string ArticleImg = "UploadedUserFiles/" + FileUpload1.FileName;
    string ArticleTitle = ArticleTitleTextBox.Text;
    string ArticleContent = ArticleContentTextBox.Text;
    string ArticleType = ArticleTypeDropdown.Text.ToString();
    string ArticleAuthor = ArticleAuthorTextBox.Text.ToString();
    string ArticleBrief = ArticleBriefTextBox.Text;
    string ArticleDateTime = DateTime.Now.ToShortTimeString();

    string query = "INSERT INTO ArticlesTBL (ArticleTitle, ArticleContent, ArticleType, ArticleImg, ArticleBrief,  ArticleDateTime, ArticleAuthor, ArticlePublished, ArticleHomeDisplay, ArticleViews) VALUES (" + ArticleTitle +", " + ArticleContent +", "+ ArticleType +" " + ArticleImg +", "+ ArticleBrief +"," + ArticleDateTime + ", "+ ArticleAuthor +",'False', 'False', '0')";

    SqlCommand myCommand = new SqlCommand(query, myConnection);

    myCommand.ExecuteNonQuery();

    //       myinfo.Text = "connection to db is made";
    myConnection.Close();

}

This question is related to c# sql database file-upload

The answer is


using System;
using System.Data;
using System.Data.SqlClient;

namespace InsertingData
{
    class sqlinsertdata
    {
        static void Main(string[] args)
        {
            try
            { 
            SqlConnection conn = new SqlConnection("Data source=USER-PC; Database=Emp123;User Id=sa;Password=sa123");
            conn.Open();
                SqlCommand cmd = new SqlCommand("insert into <Table Name>values(1,'nagendra',10000);",conn);
                cmd.ExecuteNonQuery();
                Console.WriteLine("Inserting Data Successfully");
                conn.Close();
        }
            catch(Exception e)
            {
                Console.WriteLine("Exception Occre while creating table:" + e.Message + "\t"  + e.GetType());
            }
            Console.ReadKey();

    }
    }
}

Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to database

Implement specialization in ER diagram phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' cannot be loaded Room - Schema export directory is not provided to the annotation processor so we cannot export the schema SQL Query Where Date = Today Minus 7 Days MySQL Error: : 'Access denied for user 'root'@'localhost' SQL Server date format yyyymmdd How to create a foreign key in phpmyadmin WooCommerce: Finding the products in database TypeError: tuple indices must be integers, not str

Examples related to file-upload

bootstrap 4 file input doesn't show the file name How to post a file from a form with Axios File Upload In Angular? How to set the max size of upload file The request was rejected because no multipart boundary was found in springboot Send multipart/form-data files with angular using $http File upload from <input type="file"> How to upload files in asp.net core? REST API - file (ie images) processing - best practices Angular - POST uploaded file