|
 |
|
C# เกี่ยวกับการ insert วันเวลาครับ ช่วยด้วยครับ !!! |
|
 |
|
|
 |
 |
|


Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProjectVB
{
public partial class FRM_Vb : Form
{
plant myPlant = new plant();
public FRM_Vb()
{
InitializeComponent();
}
SqlConnection th = new SqlConnection("Server=DESKTOP-35EE4RH\\SQLEXPRESS; Database=Projectcs; Trusted_Connection=True;");
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void ปดโปรแกรมToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void ยอนกลบToolStripMenuItem_Click(object sender, EventArgs e)
{
MENU main = new MENU();
main.Show();
this.Hide();
}
private void FRM_Vb_Load(object sender, EventArgs e)
{
try
{
th.Open();
Showdata();
}
catch
{
MessageBox.Show("Error");
}
}
private void Showdata()
{
string sql = "Select * From tblVb WHERE Vb_Name LIKE'%'+'" + textBox4.Text.Trim() + "'+'%'";
SqlCommand com = new SqlCommand(sql, th);
SqlDataReader dr = com.ExecuteReader();
DataTable tb = new DataTable();
if (dr.HasRows)
{
tb.Load(dr);
dataGridViewADD.DataSource = tb;
}
else
{
dataGridViewADD.DataSource = null;
}
dr.Close();
}
private void Cleardata()
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
myPlant.name = txtName.Text;
myPlant.price = Int32.Parse(txtPrice.Text);
myPlant.harvestDay = Int32.Parse(txtHarvest.Text);
myPlant.plantingDate = dateTimePicker1.Value;
myPlant.nurseryDay = Int32.Parse(txtNoA.Text);
if (myPlant.verifyNurseryDay())
{
string sql = "INSERT INTO tblVb (Vb_Name,Vb_Price,Vb_HarvestDay,Vb_Plant,Vb_NurseryDay) VALUES ('" + myPlant.name + "','" + myPlant.price.ToString() + "','" + myPlant.harvestDay.ToString() + "','" + Convert.ToDateTime(myPlant.plantingDate) + "','" + myPlant.nurseryDay.ToString() + "')";
SqlCommand com = new SqlCommand(sql, th);
com.ExecuteNonQuery();
MessageBox.Show("บันทึกเรียบร้อยแล้ว");
MessageBox.Show(myPlant.aboutPlant());
Showdata();
Cleardata();
}
else
{
MessageBox.Show("มีปัญหาแล้ววันที่อนุบาลมากกว่าวันที่เก็บเกี่ยว กรุณาตรวจสอบข้อมูลให้ถูกต้อง");
}
}
}
}
ช่วยด้วยครับ ผมทำอีกเครื่องเป็นโน๊ตบุกแล้วรันได้พอมาใช้คอมแล้วรันไม่ได้
Tag : .NET

|
|
 |
 |
 |
 |
Date :
2017-03-22 17:16:20 |
By :
natthasit |
View :
939 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดู datatype ด้วยครับ
int,varchar()
|
 |
 |
 |
 |
Date :
2017-03-22 20:48:52 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแก้ format ของ datetime ดูครับ
Convert.ToDateTime(myPlant.plantingDate) แก้เป็น
ผมมั่วน่ะ ไม่รู้คำสั่งนี้ใช้ได้ไหม
myPlant.plantingDate.ToString("yyyy-MM-dd");
แล้วก็ลองเปลี่ยนปีจาก พศ เป็น คศ ด้วยน่ะครับ
|
 |
 |
 |
 |
Date :
2017-03-23 08:13:33 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|