الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

قراءه نص وادخال البيانات في sql database

بدأه Gehad mohammed في 5 ديسمبر 2013 · 4 رد · 1,151 مشاهدة · في هندسة البرمجيات
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلا م عليكم ورحمة الله وبركاته


*****


لو سمحتم أريد عمل برنامج #C ب 


يقرأ اكثر من نص بشرط يكون  النص عربى


ويقطعه لكلمات


 ويرميه فى قاعدة البيانات sql 


 بشرط الكلمه لا تتكرر فى المقابل ىكتب لي الكلمه الواحده اتتكررت كام مره فى جميع النصوص .


المشكله  انى عملت كود ولكن على نص انجليزى لكن العربى في مشكله.


هو فى كود معين يفهم البرنامج النص العربى ويقطعه ويظهر الكلام المقطوع عربى حاولت أعمل كده طلع لوغاريتميات او(؟؟؟؟؟؟؟؟)


تانى مشكله  عملية البحث عن الكلمه فى البيانات (sql)ومعرفة هى موجوده ولا لأ ولو كانت موجوده لا تتكرر فقط أزود عداد  الكلمه (counter)


وانا عمله فى ال sql ثلات أعمده(id,word,count) 


 


 


 


****


 


 


 


 


 


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.IO;

using System.Text.RegularExpressions;

using System.Data.SqlClient;

using System.Data;

using System.Configuration;

 

namespace lib123

{

    public partial class Form1 : Form

    {

        SqlConnection sqlConn;

        SqlCommand sqlComm;

        SqlDataAdapter sqlAdptr;

 

          public Form1()

        {

            InitializeComponent();

           

           sqlConn = new SqlConnection();

           sqlComm = new SqlCommand();

           sqlAdptr = new SqlDataAdapter();

           sqlComm.Connection = sqlConn;

           sqlComm.CommandType = CommandType.Text;

           sqlConn.ConnectionString = "Data Source=007-PC\\SQLEXPRESS ;Initial Catalog= Email_DB;Integrated Security =True ";

             

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            FillGrid();

            

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

           

            if (sqlConn.State != ConnectionState.Open)

                sqlConn.Open();

 

            // sqlComm = sqlConn.CreateCommand(); 

 

            StreamReader streamReader = new StreamReader(@"C:\Users\007\Desktop\spam-email\spamenglish.txt"); //get the file

            string stringWithMultipleSpaces = streamReader.ReadToEnd(); //load file to string

            streamReader.Close();

 

            Regex r = new Regex(" +"); //specify delimiter (spaces)

            string[] words = r.Split(stringWithMultipleSpaces); //(convert string to array of words)

 

           

            int c = 1;

            string strQry = "select ISNULL( max(id),0) as id from word_tb ";

            sqlComm.CommandText = strQry;

 

            int LastID = int.Parse(sqlComm.ExecuteScalar().ToString());

           string x ;

            String st = null;

            

            for (int i = 0; i < words.Length; i++)

            {

                string y = words;

 

 

                for (int j = 0; j <LastID; j++)

                {

                 x = "select word from word_tb where id = j";

                sqlComm.CommandText = x ;

         

 

 

                if (x.Equals(y))

                {

                    c = c + 1;

                    string sql = "UPDATE    word_tb SET  count ='c'  WHERE (id = j)";

             

 

                    sqlComm.CommandText = sql;

 

                }

                else

                {

                    LastID = LastID + 1;

                    st += "INSERT INTO word_tb(id, word,count) VALUES('" + LastID + "', '" + words.ToString() + "','" + c + "');";

 

                    //st += "INSERT INTO word_tb(word) VALUES('" + words.ToString() + "');";

 

                }

                 }

            }

 

                sqlComm.CommandType = CommandType.Text;

                sqlComm.CommandText = st;

                sqlComm.ExecuteNonQuery();

 

 

                FillGrid();

 

            }

      

 

        private void FillGrid()

        {

            DataTable tbl = new DataTable();

 

          string   strQry = "select * from word_tb ";

            

            sqlComm.CommandText = strQry;

 

            sqlAdptr.SelectCommand = sqlComm;

            sqlAdptr.Fill (tbl) ;

 

 

            dataGridView1.DataSource = tbl;

 

 

 

        }

 

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

        {

 

        }

 

        //private void btnDelete_Click(object sender, EventArgs e)

        //{

        //    string str = "DELETE FROM word_tb";

        //    sqlComm.CommandType = CommandType.Text;

        //    sqlComm.CommandText = str;

        //    sqlComm.ExecuteNonQuery();

 

        //    dataGridView1.Rows.Clear();

 

 

        //            }

 

 

 

    

 

    }

    }

New Text Document (2).txt

#2

غير هذا السطر لحل مشكلة العربي

            StreamReader streamReader = new StreamReader(@"C:\Users\007\Desktop\spam-email\spamenglish.txt"); //get the file

الي

            StreamReader streamReader = new StreamReader(@"C:\Users\007\Desktop\spam-email\spamenglish.txt",Encoding.UTF8); //get the file

او غير ,Encoding.UTF8 كما تراي حتي يعمل معك العربي يوجد غيرUTF8

 

قد يفي هذا بالغرض

 protected void Button1_Click(object sender, EventArgs e)
    {
        if (sqlConn.State == ConnectionState.Closed)
            sqlConn.Open();

        sqlComm = sqlConn.CreateCommand();
        sqlComm.CommandText = "select ISNULL( max(id),0) as id from word_tb ";

        int LastID = int.Parse(sqlComm.ExecuteScalar().ToString());

        StreamReader streamReader = new StreamReader(@"C:\Users\zizo\Desktop\2.txt", Encoding.UTF8); //get the file
        string stringWithMultipleSpaces = streamReader.ReadToEnd(); //load file to string
        streamReader.Close();

        Regex r = new Regex(" +"); //specify delimiter (spaces)
        string[] words = r.Split(stringWithMultipleSpaces); //(convert string to array of words)

        var result = words.GroupBy(a => a);
        string sSql = null;
        foreach (var group in result)
        {
            LastID = LastID + 1;
            sSql= "INSERT INTO word_tb(id, word,count) VALUES('" + LastID + "', '" +group.Key+ "','" + group.Count().ToString() + "');";
            sqlComm.CommandText = sSql;
            sqlComm.ExecuteNonQuery();
        }
        sqlConn.Close{};
    }
#3
Gehad mohammed كتب:

 

السلا م عليكم ورحمة الله وبركاته

*****

لو سمحتم أريد عمل برنامج #C ب 

يقرأ اكثر من نص بشرط يكون  النص عربى

ويقطعه لكلمات

 ويرميه فى قاعدة البيانات sql 

 بشرط الكلمه لا تتكرر فى المقابل ىكتب لي الكلمه الواحده اتتكررت كام مره فى جميع النصوص .

المشكله  انى عملت كود ولكن على نص انجليزى لكن العربى في مشكله.

هو فى كود معين يفهم البرنامج النص العربى ويقطعه ويظهر الكلام المقطوع عربى حاولت أعمل كده طلع لوغاريتميات او(؟؟؟؟؟؟؟؟)

تانى مشكله  عملية البحث عن الكلمه فى البيانات (sql)ومعرفة هى موجوده ولا لأ ولو كانت موجوده لا تتكرر فقط أزود عداد  الكلمه (counter)

وانا عمله فى ال sql ثلات أعمده(id,word,count) 

 

 

 

****

 

 

 

 

 

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.IO;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
 
namespace lib123
{
    public partial class Form1 : Form
    {
        SqlConnection sqlConn;
        SqlCommand sqlComm;
        SqlDataAdapter sqlAdptr;
 
          public Form1()
        {
            InitializeComponent();
           
           sqlConn = new SqlConnection();
           sqlComm = new SqlCommand();
           sqlAdptr = new SqlDataAdapter();
           sqlComm.Connection = sqlConn;
           sqlComm.CommandType = CommandType.Text;
           sqlConn.ConnectionString = "Data Source=007-PC\\SQLEXPRESS ;Initial Catalog= Email_DB;Integrated Security =True ";
             
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            FillGrid();
            
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
           
            if (sqlConn.State != ConnectionState.Open)
                sqlConn.Open();
 
            // sqlComm = sqlConn.CreateCommand(); 
 
            StreamReader streamReader = new StreamReader(@"C:\Users\007\Desktop\spam-email\spamenglish.txt"); //get the file
            string stringWithMultipleSpaces = streamReader.ReadToEnd(); //load file to string
            streamReader.Close();
 
            Regex r = new Regex(" +"); //specify delimiter (spaces)
            string[] words = r.Split(stringWithMultipleSpaces); //(convert string to array of words)
 
           
            int c = 1;
            string strQry = "select ISNULL( max(id),0) as id from word_tb ";
            sqlComm.CommandText = strQry;
 
            int LastID = int.Parse(sqlComm.ExecuteScalar().ToString());
           string x ;
            String st = null;
            
            for (int i = 0; i < words.Length; i++)
            {
                string y = words;
 
 
                for (int j = 0; j <LastID; j++)
                {
                 x = "select word from word_tb where id = j";
                sqlComm.CommandText = x ;
         
 
 
                if (x.Equals(y))
                {
                    c = c + 1;
                    string sql = "UPDATE    word_tb SET  count ='c'  WHERE (id = j)";
             
 
                    sqlComm.CommandText = sql;
 
                }
                else
                {
                    LastID = LastID + 1;
                    st += "INSERT INTO word_tb(id, word,count) VALUES('" + LastID + "', '" + words.ToString() + "','" + c + "');";
 
                    //st += "INSERT INTO word_tb(word) VALUES('" + words.ToString() + "');";
 
                }
                 }
            }
 
                sqlComm.CommandType = CommandType.Text;
                sqlComm.CommandText = st;
                sqlComm.ExecuteNonQuery();
 
 
                FillGrid();
 
            }
      
 
        private void FillGrid()
        {
            DataTable tbl = new DataTable();
 
          string   strQry = "select * from word_tb ";
            
            sqlComm.CommandText = strQry;
 
            sqlAdptr.SelectCommand = sqlComm;
            sqlAdptr.Fill (tbl) ;
 
 
            dataGridView1.DataSource = tbl;
 
 
 
        }
 
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
 
        }
 
        //private void btnDelete_Click(object sender, EventArgs e)
        //{
        //    string str = "DELETE FROM word_tb";
        //    sqlComm.CommandType = CommandType.Text;
        //    sqlComm.CommandText = str;
        //    sqlComm.ExecuteNonQuery();
 
        //    dataGridView1.Rows.Clear();
 
 
        //            }
 
 
 
    
 
    }
    }

 

#4

قد يفى هذا بالغرض

            try
            {
                con = new SqlConnection(cs);
                con.Open();
                string ct = "select namestore,storekeeper,tel,adress,notes from storeDef where namestore= '" + textBox1.Text + "' and storekeeper= '" + textBox2.Text + "'and tel='" + textBox3.Text + "'and adress='" + textBox4.Text + "'and notes='" + textBox5.Text + "'";

                cmd = new SqlCommand(ct);
                cmd.Connection = con;

                rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    MessageBox.Show("Record Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox5.Text = "";
                   
                    
                    textBox1.Focus();


                    if ((rdr != null))
                    {
                        rdr.Close();
                    }
                    return;
                }

                con = new SqlConnection(cs);
                con.Open();

                string cb = "insert into storeDef(namestore,storekeeper,tel,adress,notes) VALUES (@d1,@d2,@d3,@d4,@d5)";

                cmd = new SqlCommand(cb);

                cmd.Connection = con;


                cmd.Parameters.Add(new SqlParameter("@d1", System.Data.SqlDbType.NChar, 20, "namestore"));
                cmd.Parameters.Add(new SqlParameter("@d2", System.Data.SqlDbType.NChar, 20, "storekeeper"));
                cmd.Parameters.Add(new SqlParameter("@d3", System.Data.SqlDbType.NChar, 50, "tel"));
                cmd.Parameters.Add(new SqlParameter("@d4", System.Data.SqlDbType.NChar, 50, "adress"));
                cmd.Parameters.Add(new SqlParameter("@d5", System.Data.SqlDbType.NChar, 50, "notes"));
                
                cmd.Parameters["@d1"].Value = textBox1.Text.Trim();
                cmd.Parameters["@d2"].Value = textBox2.Text.Trim();
                cmd.Parameters["@d3"].Value = textBox3.Text.Trim();
                cmd.Parameters["@d4"].Value = textBox4.Text.Trim();
                cmd.Parameters["@d5"].Value = textBox5.Text.Trim();
             

                cmd.ExecuteNonQuery();
                MessageBox.Show("تم عملية الحفظ بنجاح", "ادخال سجل", MessageBoxButtons.OK, MessageBoxIcon.Information);


                con.Close();


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

تم تعديل هذه المشاركة بواسطة ahmed nazzeh في 11 يناير 2014 في 18:26

#5

عذرا اخى عن ما حدث ولكن قد يفى هذا بالغرض
            try
            {
                con = new SqlConnection(cs);
                con.Open();
                string ct = "select namestore,storekeeper,tel,adress,notes from storeDef where namestore= '" + textBox1.Text + "' and storekeeper= '" + textBox2.Text + "'and tel='" + textBox3.Text + "'and adress='" + textBox4.Text + "'and notes='" + textBox5.Text + "'";

                cmd = new SqlCommand(ct);
                cmd.Connection = con;

                rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    MessageBox.Show("Record Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox5.Text = "";
                   
                    
                    textBox1.Focus();


                    if ((rdr != null))
                    {
                        rdr.Close();
                    }
                    return;
                }

                con = new SqlConnection(cs);
                con.Open();

                string cb = "insert into storeDef(namestore,storekeeper,tel,adress,notes) VALUES (@d1,@d2,@d3,@d4,@d5)";

                cmd = new SqlCommand(cb);

                cmd.Connection = con;


                cmd.Parameters.Add(new SqlParameter("@d1", System.Data.SqlDbType.NChar, 20, "namestore"));
                cmd.Parameters.Add(new SqlParameter("@d2", System.Data.SqlDbType.NChar, 20, "storekeeper"));
                cmd.Parameters.Add(new SqlParameter("@d3", System.Data.SqlDbType.NChar, 50, "tel"));
                cmd.Parameters.Add(new SqlParameter("@d4", System.Data.SqlDbType.NChar, 50, "adress"));
                cmd.Parameters.Add(new SqlParameter("@d5", System.Data.SqlDbType.NChar, 50, "notes"));
                
                cmd.Parameters["@d1"].Value = textBox1.Text.Trim();
                cmd.Parameters["@d2"].Value = textBox2.Text.Trim();
                cmd.Parameters["@d3"].Value = textBox3.Text.Trim();
                cmd.Parameters["@d4"].Value = textBox4.Text.Trim();
                cmd.Parameters["@d5"].Value = textBox5.Text.Trim();
             

                cmd.ExecuteNonQuery();
                MessageBox.Show("تم عملية الحفظ بنجاح", "ادخال سجل", MessageBoxButtons.OK, MessageBoxIcon.Information);


                con.Close();


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

مواضيع مشابهة