I'm newer to c#.I'm creating datatable(sql) which has 6 columns.Here is my table definition
spiceID varchar not allow null (primary key)
spiceName text not allow null
mfddate Datetime not allow null
expdate Datetime not allow null
storeNo varchar not allow null
storeamount float not allow null
priceper1kg float not allow null
here I not allow nulls.But If i not insert value to above columns it won't show any error msg & accept what i entre.
plz help me to solve this quickly
Here is my code.I'm creating store keeping data project
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Ruhunu_spices_PVT_LTD
{
public partial class Product : Form
{
SqlConnection conn1 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Sachintha\\Desktop\\Ruhunu spices(PVT)LTD\\Ruhunu spices(PVT)LTD\\Rspices.mdf;Integrated Security=True;User Instance=True");
public Product()
{
InitializeComponent();
}
private void Product_Load(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
this.Hide();
login_view f2 = new login_view();
f2.ShowDialog();
}
private void button1_Click(object sender, EventArgs e)
{
SqlCommand comm1 = new SqlCommand("INSERT INTO productT(spiceID,spiceName,MFDdate,EXPdate,storeNo,storeAmount,price1kg)Values(@textBox1,@comboBox1,'" + dateTimePicker1.Value.Date + "','" + dateTimePicker2.Value.Date + "',@textBox2,@textBox3,@textBox4)", conn1);
comm1.Parameters.Add("@textBox1", textBox1.Text);
comm1.Parameters.Add("@comboBox1", comboBox1.Text);
comm1.Parameters.Add("@textBox2", textBox2.Text);
comm1.Parameters.Add("@textBox3", textBox3.Text);
comm1.Parameters.Add("@textBox4", textBox4.Text);
conn1.Open();
comm1.ExecuteNonQuery();
MessageBox.Show("one row inserted");
textBox1.Clear();
textBox2.Clear();
comboBox1.Text = "";
textBox3.Clear();
textBox4.Clear();
dateTimePicker1.Value = DateTime.Today;
dateTimePicker2.Value = DateTime.Today;
conn1.Close();
}
private void button5_Click(object sender, EventArgs e)
{
String commandstring;
commandstring =string.Format( "SELECT * FROM productT WHERE spiceID='{0}'", textBox1.Text.Trim());
SqlDataReader dr1 = null;
SqlCommand com2 = new SqlCommand(commandstring, conn1);
try
{
conn1.Open();
}
catch
{
MessageBox.Show("error in seaching", "message", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
}
dr1 = com2.ExecuteReader();
if (dr1.Read())
{
comboBox1.Text = dr1[1].ToString();
dateTimePicker1.Value = (DateTime)dr1[2];
dateTimePicker2.Value = (DateTime)dr1[3];
textBox2.Text = dr1[4].ToString();
textBox3.Text = dr1[5].ToString();
textBox4.Text = dr1[6].ToString();
}
else
{
MessageBox.Show("Record can not found");
}
dr1.Close();
conn1.Close();
}
}
}