Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
GeneralRe: Want Opinion on school assignment Pin
OriginalGriff13-Feb-15 4:34
mveOriginalGriff13-Feb-15 4:34 
GeneralRe: Want Opinion on school assignment Pin
Eddy Vluggen13-Feb-15 4:52
professionalEddy Vluggen13-Feb-15 4:52 
GeneralRe: Want Opinion on school assignment Pin
Truck5313-Feb-15 5:01
Truck5313-Feb-15 5:01 
GeneralRe: Want Opinion on school assignment Pin
Dave Kreskowiak13-Feb-15 3:03
mveDave Kreskowiak13-Feb-15 3:03 
GeneralRe: Want Opinion on school assignment Pin
Truck5313-Feb-15 5:01
Truck5313-Feb-15 5:01 
GeneralRe: Want Opinion on school assignment Pin
Pete O'Hanlon13-Feb-15 3:18
mvePete O'Hanlon13-Feb-15 3:18 
GeneralRe: Want Opinion on school assignment Pin
Truck5313-Feb-15 5:01
Truck5313-Feb-15 5:01 
Questionhow to insert wifi scan data into sql table Pin
Olu_0112-Feb-15 18:03
Olu_0112-Feb-15 18:03 
Urgent assist required. Can someone help pls, i have scanned wifi data in C# that i have split into required form MAC,SSID and RSSi . i want when i push a button the results are inserted into an sql table that i already created. and if i push the buton again it stops inserting. I have tried several methods and could not get it to work, Will appreciate assist

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace WICED_SERIALPORT_TEST
{
    public partial class Form1 : Form

    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                comboBox1.Items.Add(port);
            }

        }
        //
        string t;
        private void button2_Click(object sender, EventArgs e)
        {

            t = comboBox1.Text.ToString();
            sErial(t);
            
        }
        //
        SerialPort sp;
        void sErial(string Port_name)
        {
            sp = new SerialPort(Port_name, 115200, Parity.None, 8, StopBits.One);
            sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            sp.Open();
        }
        // 
        private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;
            string msg = string.Empty;
            bool canCont = false;

            while (!canCont)
            {
                msg += sp.ReadLine();
                if (msg.Contains("Scan complete "))
                {
                    canCont = true;
                }
            }

            //string w = sp.ReadLine();
            //string w = sp.ReadExisting();

            // string msg = sp.ReadExisting();

            string[] msgArr = msg.Split('\r');

            Invoke(new Action(() => listBox1.Items.Clear()));


            List<string[]> list = new List<string[]>();
            List<Networks> Scan = new List<Networks>();

            for (int i = 0; i < msgArr.Length; i++)
            {
                list.Add(msgArr[i].Split(new string[] { "  " }, StringSplitOptions.RemoveEmptyEntries));
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (i > 2)
                {
                    if (list[i].Length > 4)
                    {
                        int numOfSplits = 0;
                        List<string> tempList = new List<string>();

                        for (int ii = 0; ii < list[i].Length; ii++)
                        {
                            if (numOfSplits < 6)
                            {
                                string[] temp1 = list[i][ii].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                                numOfSplits += temp1.Length;

                                for (int iii = 0; iii < temp1.Length; iii++)
                                {
                                    tempList.Add(temp1[iii]);
                                }
                            }
                            else
                            {
                                tempList.Add(list[i][ii]);
                            }
                        }

                        Scan.Add(new Networks()
                        {
                            ID = Convert.ToInt32(tempList[0]),
                            NetworkType = tempList[1],
                            MAC = tempList[2],
                            RSSi = Convert.ToInt32(tempList[3]),
                            Rate = Convert.ToDouble(tempList[4]),
                            Channel = Convert.ToInt32(tempList[5]),
                            Security = tempList[6],
                            SSID = tempList[7],
                        });
                    }
                }
            }
            if (msg != String.Empty)
            {
                Invoke(new Action(() => richTextBox1.AppendText(msg)));

            }
            for (int i = 0; i < Scan.Count; i++)
            {
                Invoke(new Action(() => listBox1.Items.Add(Scan[i].MAC)));
                Invoke(new Action(() => listBox2.Items.Add(Scan[i].RSSi)));
                Invoke(new Action(() => listBox3.Items.Add(Scan[i].SSID)));

                msg = string.Empty;
                list.Clear();
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

            
            
           
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void richTextBox2_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        public SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\AP_SCAN_DATA.mdf;Integrated Security=True");
        private void button3_Click(object sender, EventArgs e)
        {
            

            using (SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\AP_SCAN_DATA.mdf;Integrated Security=True"))
{
    using (SqlCommand command = new SqlCommand())
    {
        command.Connection = connection;            // <== lacking
        command.CommandType = CommandType.Text;
        command.CommandText = "INSERT into LOCATIONSCAN ((Scan[i].SSID),(Scan[i].MAC), (Scan[i].RSSi)) VALUES (@SSID, @MAC, @RSSi)";
        command.Parameters.AddWithValue("@SSID", listBox1);
        command.Parameters.AddWithValue("@MAC", listBox2);
        command.Parameters.AddWithValue("@RSSi",listBox3);

        try
        {
            connection.Open();
            int recordsAffected = command.ExecuteNonQuery();
        }
        catch(SqlException)
        {
            // error here
        }
        finally
        {
            connection.Close();
        }
    }
}





        }
       
    }
}

AnswerRe: how to insert wifi scan data into sql table Pin
Wendelius12-Feb-15 18:31
mentorWendelius12-Feb-15 18:31 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0112-Feb-15 23:17
Olu_0112-Feb-15 23:17 
GeneralRe: how to insert wifi scan data into sql table Pin
Wendelius13-Feb-15 3:01
mentorWendelius13-Feb-15 3:01 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0116-Feb-15 12:16
Olu_0116-Feb-15 12:16 
AnswerRe: how to insert wifi scan data into sql table Pin
Chris Quinn13-Feb-15 0:29
Chris Quinn13-Feb-15 0:29 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0116-Feb-15 12:15
Olu_0116-Feb-15 12:15 
AnswerRe: how to insert wifi scan data into sql table Pin
Richard Deeming13-Feb-15 2:39
mveRichard Deeming13-Feb-15 2:39 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0116-Feb-15 12:12
Olu_0116-Feb-15 12:12 
Questionhow can i call a whole word function in update when lives =0... whole word fun displays whole word... but i am facing different errors when i call it in update.. Pin
Member 1144879612-Feb-15 17:35
Member 1144879612-Feb-15 17:35 
SuggestionRe: how can i call a whole word function in update when lives =0... whole word fun displays whole word... but i am facing different errors when i call it in update.. Pin
Richard MacCutchan12-Feb-15 22:33
mveRichard MacCutchan12-Feb-15 22:33 
Questionhow can i show a pop up of high scores for few seconds when high scores are achieved in c# Pin
Member 1144879612-Feb-15 17:31
Member 1144879612-Feb-15 17:31 
AnswerRe: how can i show a pop up of high scores for few seconds when high scores are achieved in c# Pin
Pete O'Hanlon12-Feb-15 19:21
mvePete O'Hanlon12-Feb-15 19:21 
QuestionC# and AccDB: Products with category in combo box. Pin
sdfsdfsdfewrew3feff12-Feb-15 16:04
sdfsdfsdfewrew3feff12-Feb-15 16:04 
AnswerRe: C# and AccDB: Products with category in combo box. Pin
Dave Kreskowiak12-Feb-15 16:54
mveDave Kreskowiak12-Feb-15 16:54 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
sdfsdfsdfewrew3feff15-Feb-15 14:35
sdfsdfsdfewrew3feff15-Feb-15 14:35 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
Dave Kreskowiak15-Feb-15 16:20
mveDave Kreskowiak15-Feb-15 16:20 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
sdfsdfsdfewrew3feff16-Feb-15 2:51
sdfsdfsdfewrew3feff16-Feb-15 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.