none
ocr RRS feed

  • Question

  • how to store the array result in database.. using c#

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Tesseract;
    using System.Drawing;

    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
       string[] strarr= new string[1000];
        if (args == null) throw new ArgumentNullException("args");
                Bitmap img = new Bitmap("ty.jpg");
                TesseractEngine engine = new TesseractEngine("./tessdata", "eng", EngineMode.Default);
                Page page = engine.Process(img, PageSegMode.Auto);
                strarr[0] = (page.GetText());

                Console.WriteLine(strarr[0]);

                Console.Read();

    CODE IS THIS

    ARRAY CONTENT STORE IN DATABASE

    Sunday, February 3, 2019 10:49 AM

All replies

  • Hi,

    what kind of database? SQL, MongoDB ...

    Which array do you want to store? strarr?

    Sunday, February 3, 2019 8:06 PM
  • Hi monika Pathak,

    Thank you for posting here.

    For your question, what is the database you want to use?

    If you use SQL database, you could convert string array to string with "," or other symbols to split and use varchar(MAX) to define your data type of SQL database. Here is the code about save string to SQL database.

      string strConn = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=Database.mdf;Integrated Security=True;Connect Timeout=30";
    
                using (SqlConnection cn = new SqlConnection(strConn))
                {
                    cn.Open();
                    using (SqlCommand cm = new SqlCommand())
                    {
                        cm.Connection = cn;
                        cm.CommandType = CommandType.Text;
                        cm.CommandText = "insert into Image (array) values(@file)";
                        SqlParameter spFile = new SqlParameter("@file", SqlDbType.VarChar);
                        spFile.Value = s; //s is the string which I convert fron strarr
                        cm.Parameters.Add(spFile);
                        cm.ExecuteNonQuery();
                    }
                }

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Tuesday, February 5, 2019 2:52 AM
    Monday, February 4, 2019 3:29 AM
    Moderator