Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
Y

yueru

@yueru
About
Posts
22
Topics
8
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • ExecuteQuery and ExecuteReader
    Y yueru

    I don't know why when I use select with ExecuteQuery my result will have repeated the lastes line. And my friend adviced me that I should use ExecuteReader now it's work What's the different ??? here is my code !!

    public void Add()
    {
    if (File.Exists("" + info + ".db"))
    {
    sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=False;Compress=True;");
    sql_con.Open();
    sql_cmd = sql_con.CreateCommand();
    sql_cmd.CommandText = "drop table par ;";
    sql_cmd.ExecuteNonQuery();
    }
    else
    {
    sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=True;Compress=True;");
    sql_con.Open();
    sql_cmd = sql_con.CreateCommand();
    }
    sql_cmd.CommandText = "create table par (Date nvarchar(20), Time nvarchar(10), Linein NVARCHAR(20), Lineout NVARCHAR(20), Number NVARCHAR(20), Status nvarchar(10),Duration int(20), Cost nvarchar(20), Detail nvarchar(10), Network nvarchar(10));";
    sql_cmd.ExecuteNonQuery();
    StreamReader reader = new StreamReader(inputfilename);
    string line = reader.ReadLine();
    while (line != null)
    {
    string NNDuration = line.Replace("'", "''");
    string Date = line.Substring(12, 8);
    if (line[11] == '=')
    {
    string Time = line.Substring(21, 5);
    string Linein = line.Substring(27, 10);
    string Lineout = line.Substring(38, 1);
    if (string.Compare(Lineout, "0") >= 0 && string.Compare(Lineout, "9") <= 0)
    {
    string Number = line.Substring(40, 20);
    string Status = line.Substring(61, 3);
    string NDuration = NNDuration.Substring(65, 10);
    string b = NDuration.Substring(2, 2);
    string c = NDuration.Substring(6, 2);
    int y = Convert.ToInt32(b);
    int l = Convert.ToInt32(c);
    int Duration = y + l;
    string OCost = line.Substring(73, 5);
    string Cost = OCost.Trim();
    string Detail = line.Substring(79, 3);
    string Network = line.Substring(

    Database database sysadmin question announcement

  • Print Datagridview
    Y yueru

    Thank you very much   for helping ^^ It's useful and I'm having a problem with datagridview right but I gonna deal with it. :) Although it's so hurt ,I still choose love.

    C# graphics

  • Print Datagridview
    Y yueru

    I've already done every article it's seem to be useful but can't fulfill my request. I've just wanted to print all of my data from my datagrid. I have code it can run but this   result is far from my thinking here is code

    private void button3_Click(object sender, EventArgs e)
    {
    printDocument1.Print();
    }
    public void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
    PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle(new Point(0, 0), this.Size));
    this.InvokePaint(dataGridView1, myPaintArgs);

    when i click on button3 it can print but show just only i can see from   datagrid not all of datagrid Thank in advance !!!!

    C# graphics

  • Print Datagrid
    Y yueru

    I just want to print and I've got the code msdn http://msdn.microsoft.com/en-us/library/aa287528(VS.71).aspx[^]

    private void button3_Click(object sender, EventArgs e)
    {
    printDocument1.Print();
    }

        private void printDocument1\_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle(new Point(0, 0), this.Size));
            InvokePaint(dataGridView1, myPaintArgs);
        }
    

    When I clicked at button 3 ,I got just only page and nothing in side What's wrong with my code

    C# graphics visual-studio com

  • How to create an exist database [modified]
    Y yueru

    If I has database but in sqlite command can't write into exists dataase

    sql_con = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");

    how to command that write whatever database is exist !!! I 've already use command but it's not work

    if (File.Exists("" + info + ".db"))
    {
    sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=False;Compress=True;");
    sql_con.Open();
    sql_cmd = sql_con.CreateCommand();
    sql_cmd.CommandText = "drop table par ;";
    sql_cmd.ExecuteNonQuery();
    }
    else
    {
    sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=True;Compress=True;");

            }
    
           //  FileStream fileStream = new FileStream(@" " + info + ".db", FileMode.Create);
           
                
            sql\_con.Open();
            sql\_cmd = sql\_con.CreateCommand();
            sql\_cmd.CommandText = "create table par (Date nvarchar(20), Time nvarchar(10), Linein NVARCHAR(20), Lineout NVARCHAR(20), Number NVARCHAR(20), Status nvarchar(10),Duration int(20), Cost nvarchar(20), Detail nvarchar(10), Network nvarchar(10));";
            sql\_cmd.ExecuteNonQuery();
    

    modified on Thursday, May 14, 2009 11:03 PM

    Database database sqlite sysadmin tutorial announcement

  • Bug with between sql command
    Y yueru

    Actully I've get the code but it 's too longgg

    private void button4_Click(object sender, EventArgs e)
    {

            sql\_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=False;Compress=True;");
            sql\_con.Open();
            sql\_cmd = sql\_con.CreateCommand();
            if ((radioButton1.Checked == true))
            {
                if (textBox10.Text != "")
                {
                    if (textBox7.Text != "")
                    {
                        string CommandText = "select \* from  par where  Time between '" + textBox7.Text + "%' and '" + textBox13.Text + "%' and Date like '" + textBox6.Text + "%'  and Linein like'" + textBox8.Text + "%' and Lineout like '" + textBox9.Text + "%'and Duration >= " + textBox10.Text + " ;"; 
                        DB = new SQLiteDataAdapter(CommandText, sql\_con);//นำข้อมูลออกมา
                        DS.Reset();
                        DB.Fill(DS);//นาม ข้อมูลปายส่ายนาย ดาต้าเซด
                        DT = DS.Tables\[0\];
                        dataGridView1.DataSource = DT;
                        int rowCount = ((DataTable)this.dataGridView1.DataSource).Rows.Count;
                        textBox12.Text = rowCount.ToString();
                        sql\_con.Close();
                        MessageBox.Show("OK");
                    }
                    else
                    {
                        string CommandText = "select \* from  par where Date like '" + textBox6.Text + "%'  and Linein like'" + textBox8.Text + "%' and Lineout like '" + textBox9.Text + "%'and Duration >= " + textBox10.Text + " ;";
                        DB = new SQLiteDataAdapter(CommandText, sql\_con);//นำข้อมูลออกมา
                        DS.Reset();
                        DB.Fill(DS);//นาม ข้อมูลปายส่ายนาย ดาต้าเซด
                        DT = DS.Tables\[0\];
                        dataGridView1.DataSource = DT;
                        int rowCount = ((DataTable)this.dataGridView1.DataSource).Rows.Count;
                        textBox12.Text = rowCount.ToString();
                        sql\_con.Close();
                        MessageBox.Show("OK");
                    }
                }
                else
                {
                    if (textBox7.Text != "")
                    {
                        string CommandText = "select \* from  par where  Time between '" + textBox7.Text + "%' and '" + textBox13.Text + "%' and Date like '" + textBox6.Text + "%'  and Line
    
    C# database help

  • Bug with between sql command
    Y yueru

    I want to search it but if I didn't insert value in textBox7 or textBox13 it will not show anything( but I 've inserted data in another textbox)

    string CommandText = "select * from par where Time between '" + textBox7.Text + "%' and '" + textBox13.Text + "%' and Date like '" + textBox6.Text + "%' and Linein like'" + textBox8.Text + "%' and Lineout like '" + textBox9.Text + "%'and Duration <= " + textBox10.Text + " ;";

    but if i insert data into it it will show like this command It's mean that every function is subset of between right ?????

    C# database help

  • Bug with between sql command
    Y yueru

    I've used sql command here is my code

    string CommandText = "select * from par where Time between '" + textBox7.Text + "%' and '" + textBox13.Text + "%' and Date like '" + textBox6.Text + "%' and Linein like'" + textBox8.Text + "%' and Lineout like '" + textBox9.Text + "%'and Duration >= " + textBox10.Text + " ;";
    DB = new SQLiteDataAdapter(CommandText, sql_con);//นำข้อมูลออกมา
    DS.Reset();
    DB.Fill(DS);//นาม ข้อมูลปายส่ายนาย ดาต้าเซด
    DT = DS.Tables[0];
    dataGridView1.DataSource = DT;
    int rowCount = ((DataTable)this.dataGridView1.DataSource).Rows.Count;
    textBox12.Text = rowCount.ToString();
    sql_con.Close();

    It has problem that if I haven't insert value to Time it will not show anything but if I take the value to it I can run the search and It'll take the value to mydatagrid :confused:

    C# database help

  • convert.ToInt32
    Y yueru

    Wowwww It's so short and simply but I've never knoww. :) thx very much Code is ok but I 've just want to know how to decrease time to do it coz I have 10,100 data and it took a long time.

    C# help question

  • convert.ToInt32
    Y yueru

    Thank you I 've got it even if I've made alot of mistake like u said now is my code

    string Duration = line.Replace("'", "[']");
    string LineOO = line.Replace("#", "[#]");
    string Date = line.Substring(12, 8);
    if (line.Substring(11, 1) == "=")
    {
    string Time = line.Substring(21, 5);
    string Linein = line.Substring(27, 10);
    string Lineout = LineOO.Substring(38, 1);

                    if ((string.Compare(Lineout, "0") > 0 || string.Compare(Lineout, "0") == 0) && (string.Compare(Lineout, "9") < 0 || string.Compare(Lineout, "9") == 0))
                    {
                       
                        //int g = line.Length;
                        //string Number = line.Substring(40, g - 40);
                        string Number = line.Substring(40, 20);
                        string Status = line.Substring(61, 3);
                      string NDuration = Duration.Substring(64, 10);
                        
    
                       // string a = Duration.Substring(1, 2);
                               string b = NDuration.Substring(3, 2);
                        string c = NDuration.Substring(6, 2);
                       // int s = Convert.ToInt32(a);
                        int y = Convert.ToInt32(b);
                        int l = Convert.ToInt32(c);
                        int NDura =   y + l;
              // reject a but if a has value 00 it mean that I can't use it right?
                        string Cost = line.Substring(75, 3);
                        string Detail = line.Substring(79, 2);
                        string Network = line.Substring(82, 8);
    

    :) and it work Thx

    C# help question

  • convert.ToInt32
    Y yueru

    line = "==XXXT08746=05/01/09 15:13 112 4 IT 0:01'22 0 #2 ";
    string Duration = line.Substring(64, 9).Replace("#","[#]");
    int s = Convert.ToInt32(Duration.Substring(1, 2));
    int s = Convert.ToInt32(Duration.Substring(1, 2));
    int y = Convert.ToInt32(Duration.Substring(3, 2));
    int l = Convert.ToInt32(Duration.Substring(6, 2));
    int NDura = s + y + l;

    ---->>>> Error System.FormatException: Input string was not in a correct format. So what should I do with this ?

    C# help question

  • Problem with Datagrid
    Y yueru

    I've already tried It's still "no such table: par" And what the problem with the # in sql_cmd.ExecuteNonQuery();

    C# database help announcement

  • Problem with Datagrid
    Y yueru

    It's said that "Don't have par(my table)" and alway have error with sql_cmd.ExecuteNonQuery(); coz my file have # it can't read # <pre> private SQLiteConnection sql_con; private SQLiteCommand sql_cmd; private SQLiteDataAdapter DB; private DataSet DS = new DataSet(); private DataTable DT = new DataTable(); private void SetConnection() { sql_con = new SQLiteConnection("Data Source=pare.db;Version=3;New=False;Compress=True;"); // sql_con = new SQLiteConnection("Data Source=pare.db;Version=3;New=True;Compress=True;"); if I want to create new database } private void ExecuteQuery(string txtQuery) { <big> sql_con.Open();</big> sql_cmd = sql_con.CreateCommand(); sql_cmd.CommandText = txtQuery; <big> sql_cmd.ExecuteNonQuery(); </big> sql_con.Close(); } </pre> <pre> private void LoadData() { sql_con.Open(); sql_cmd = sql_con.CreateCommand(); string CommandText = "select * from par"; DB = new SQLiteDataAdapter(CommandText, sql_con);//นำข้อมูลออกมา DS.Reset(); DB.Fill(DS);//นาม ข้อมูลปายส่ายนาย ดาต้าเซด DT = DS.Tables[0]; dataGridView1.DataSource = DT; sql_con.Close(); } private void button2_Click(object sender, EventArgs e) { SetConnection(); LoadData(); } </pre> It has error on the BIG :doh: NO MORE TEAR

    C# database help announcement

  • Split text file by Fixed Length
    Y yueru

    Forget about Fixed length it's not my point NOw I 've got the code

    String inputfilename = "";
    private void Add(){

    StreamReader reader = new StreamReader(inputfilename);
    //MessageBox.Show(inputfilename);

            string line = reader.ReadLine();
    
            while (line != null)
            {
                string Date = line.Substring(12, 8);
                if (line.Substring(11, 1) == "=")
                {
                    string Time = line.Substring(21, 5);
                    string Linein = line.Substring(27, 10);
                    string Lineout = line.Substring(38, 1);
                    
    
                    if ((string.Compare(Lineout, "0") > 0 || string.Compare(Lineout, "0") == 0) && (string.Compare(Lineout, "9") < 0 || string.Compare(Lineout, "9") == 0))
                    {
                        //int g = line.Length;
                        //string Number = line.Substring(40, g - 40);
                        string Number = line.Substring(40, 20);
                        string Status = line.Substring(61, 3);
                         string Duration = line.Substring(65, 9);
                          string Cost = line.Substring(75, 3);
                         string Detail = line.Substring(79, 2);
                         string Network = line.Substring(82, 8);
                       // trim whitespace from both ends of the elements
    
                        string txtSQLQuery = "insert into par values('" + Date + "','" + Time + "','" + Linein + "','" + Lineout + "','" + Number + "','" + Status + "','" + Duration + "','" + Cost + "','" + Detail + "','" + Network + "')";
                        ExecuteQuery(txtSQLQuery);
    
                        //MessageBox.Show(line);
    
    
                        textBox6.Text = textBox6.Text + "\\r\\n" + Date + " " + Time + " " + Linein + " " + Lineout + " " + Number + " ";
                    }
                    else
                    {
                        textBox5.Text = line + "\\r\\n" + textBox5.Text;
    
                    }
                }
                else
                {
                    textBox5.Text = line + "\\r\\n" + textBox5.Text;
                }
                line = reader.ReadLine();
            }
    
            MessageBox.Show("End while loop");
        }
    

    thx for all comment +_! :)

    C# tutorial

  • Split text file by Fixed Length
    Y yueru

    Yepp I've done it but It still can't run The first I assign

    textBox4.Text = reader.ReadLine.ToString();

    but it said I used wrong method so I change it to be

    textBox4.Text = reader.ReadLine.();

    It's no error but can't use I don't know why TwT Message when it error http://www.uppicth.com/show.php?filex=e5d4b8cd0fec144f140ded8bcbcfe23a.JPG[^]

    modified on Thursday, April 30, 2009 6:15 AM

    C# tutorial

  • Split text file by Fixed Length
    Y yueru

    I don't know why I add

    string line = reader.ReadLine();
    while (line != null)
    {
    string newLine = line.Replace("=", " ");
    string[] vals = newLine.Split(' ');//use this if you need values seperate for table
    //do something like add newLine to table, or add the string in the vals array
    line = reader.ReadLine();
    }
    //I add this
    textBox4.Text = reader.ReadLine();
    reader.Close();

    and then when I click in button 2 it 's nothing but button 1 can use Thank in advance

    C# tutorial

  • Split text file by Fixed Length
    Y yueru

    Thank you for a example for multiple textfile So do u have example about split ? Thank you in advance

    C# tutorial

  • Split text file by Fixed Length
    Y yueru

    It has error on

    StreamReader reader = new StreamReader(info.Filname);

    can I change it to b

    StreamReader reader = new StreamReader(o.FileName);

    and it can't run on Button2 I don't know why

    C# tutorial

  • Split text file by Fixed Length
    Y yueru

    Yeppp I've knowed how to read I use

    using System.IO;
    namespace WindowsApplication23
    {
    public partial class Form1 : Form
    {
    OpenFileDialog o;
    FileInfo info;
    public Form1()
    {
    InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
    o = new OpenFileDialog();
    if (o.ShowDialog() == DialogResult.OK)
    {
    info = new FileInfo(o.FileName);
    label1.Text = info.ToString();
    }
    }
    private void button2_Click(object sender, EventArgs e)
    {
    StreamReader reader = info.OpenText();
    textBox1.Text = reader.ReadToEnd().ToString();
    reader.Close();
    }
    }
    }

    but it read all of my file I just want it from ==lo12365=12/08/05 12.30 lo op ==lo12589=13/08/04 12.15 li oo ==lo89099=18/05/09 12.10 io io tobe lo12365 12/08/05 12.30 lo op lo12589 13/08/04 12.15 li oo lo89099 18/05/09 12.10 io io and insert it to my table thx in advance

    C# tutorial

  • Split text file by Fixed Length
    Y yueru

    So how to ???

    C# tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups