Click here to Skip to main content
14,301,797 members
   

ASP.NET

 
AnswerRe: How do I get my link to point to server and play a .WAV audio? Pin
Richard Deeming23-May-19 7:24
mveRichard Deeming23-May-19 7:24 
GeneralRe: How do I get my link to point to server and play a .WAV audio? Pin
samflex23-May-19 9:29
membersamflex23-May-19 9:29 
Questionbookmark Pin
Member 1441910022-May-19 4:00
memberMember 1441910022-May-19 4:00 
AnswerRe: bookmark Pin
Vinod Jangle28-May-19 10:37
memberVinod Jangle28-May-19 10:37 
QuestionEmail Based OTP Verification for new user registration Pin
VIRENDRA TEMBHARE20-May-19 20:19
memberVIRENDRA TEMBHARE20-May-19 20:19 
AnswerRe: Email Based OTP Verification for new user registration Pin
Richard MacCutchan20-May-19 21:02
protectorRichard MacCutchan20-May-19 21:02 
AnswerRe: Email Based OTP Verification for new user registration Pin
Richard Deeming21-May-19 0:37
mveRichard Deeming21-May-19 0:37 
QuestionCannot insert the value NULL into column 'Status_Id', table 'ITInventory.dbo.Workstations'; column does not allow nulls. INSERT fails. Pin
SuperJWP20-May-19 7:32
memberSuperJWP20-May-19 7:32 
Hi, I am using Visual Studio Community 2017 and i created a table called Workstations
with my .cs code i am traing to insert data into the table. I am also struggling to add the dateTimePicker into the Purch_Date and WExpiry_Date fields. i am receive this error when doing a debug on the script "
Cannot insert the value NULL into column 'Status_Id', table 'ITInventory.dbo.Workstations'; column does not allow nulls. INSERT fails.
"below is my code. Hope someone can help me with this. Thank you in advance

.cs code:

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;
using System.Configuration;


namespace InventoryStock
{
    public partial class Workstations : Form
    {
        public object WExpiry_Date { get; private set; }

        public Workstations()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void Workstations_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'iTInventoryDataSet.Workstations' table. You can move, or remove it, as needed.
            this.workstationsTableAdapter.Fill(this.iTInventoryDataSet.Workstations);
            comboBox3.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            SqlConnection con = new SqlConnection(@"Data Source=sh-jasonk\dev;Initial Catalog=ITInventory;Integrated Security=True");
            //Insert Logic
            con.Open();
            bool Wkst_Status = false;
            if (comboBox3.SelectedIndex == 0)
            {
                Wkst_Status = true;
            }
            else
            {
                Wkst_Status = false;
            }

            SqlCommand cmd = new SqlCommand
        
            (@"INSERT INTO [dbo].[Workstations]
           (
           [Emp_Name]
           ,[Emp_Surname]
           ,[Department]
           ,[Company]
           ,[Hostname]
           ,[Wkst_Status]
           ,[Make]
           ,[Model]
           ,[SerialNumber]
           ,[ProductNumber]
           ,[Purch_Date]
           ,[WExpiry_Date]
           ,[Memory]
           ,[Processor]
           ,[HDD]
           ,[OS])
          
     VALUES
           ('" + txtName.Text + "','" + txtSurname.Text + "','" + comboBox1.Text + "','" + comboBox2.Text + "','" + txtHostName.Text + "','" + comboBox3.SelectedIndex + "','" + txtMake.Text + "','" + txtModel.Text + "','" + txtSN.Text + "','" + txtPN.Text + "','" + dateTimePicker1.Value.ToString("yyyy/MM/dd") + "','" + dateTimePicker1.Value.ToString("yyyy/MM/dd") + "','" + txtMem.Text + "','" + txtProc.Text + "','" + txtHDD.Text + "','" + txtOS.Text + "')",con);

         
            //Conversion failed here
            cmd.ExecuteNonQuery();
            con.Close();
       
            //Reading Data
            SqlDataAdapter sda = new SqlDataAdapter(@"Select  [Emp_Name][Emp_Surname],[Department],[Company],[Hostname],[Wkst_Status],[Make],[Model]
                                                             ,[SerialNumber],[ProductNumber],[Purch_Date],[WExpiry_Date],[Memory],[Processor],[HDD]
                                                             ,[OS] From [dbo].[Workstations]", con);
            
            DataTable dt = new DataTable();
            sda.Fill(dt);
            dataGridView1.Rows.Clear();

            foreach (DataRow item in dt.Rows)
            {
                int n = dataGridView1.Rows.Add();
                dataGridView1.Rows[n].Cells[0].Value = item["Emp_Name"].ToString();
                dataGridView1.Rows[n].Cells[1].Value = item["Emp_Surname"].ToString();
                dataGridView1.Rows[n].Cells[2].Value = item["Department"].ToString();
                dataGridView1.Rows[n].Cells[3].Value = item["Company"].ToString();
                dataGridView1.Rows[n].Cells[4].Value = item["Hostname"].ToString();
                if ((bool)item["Wkst_Status"])
                {
                    dataGridView1.Rows[n].Cells[5].Value = "Active";
                }
                else
                {
                    dataGridView1.Rows[n].Cells[5].Value = "Inactive";
                }

              
                dataGridView1.Rows[n].Cells[6].Value = item["Make"].ToString();
                dataGridView1.Rows[n].Cells[7].Value = item["Model"].ToString();
                dataGridView1.Rows[n].Cells[8].Value = item["SerialNumber"].ToString();
                dataGridView1.Rows[n].Cells[9].Value = item["ProductNumber"].ToString();
                dataGridView1.Rows[n].Cells[10].Value = item["Purch_Date"].ToString();
                dataGridView1.Rows[n].Cells[11].Value = item["WExpiry_Date"].ToString();
                dataGridView1.Rows[n].Cells[12].Value = item["Memory"].ToString();
                dataGridView1.Rows[n].Cells[13].Value = item["Processor"].ToString();
                dataGridView1.Rows[n].Cells[14].Value = item["HDD"].ToString();
                dataGridView1.Rows[n].Cells[15].Value = item["OS"].ToString();
            }

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

        }
    }
}


my SQL table create code

USE [ITInventory]
GO

/****** Object:  Table [dbo].[Workstations]    Script Date: 2019/05/20 19:18:26 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Workstations](
	[Emp_Id] [int] IDENTITY(1,1) NOT NULL,
	[Emp_Name] [varchar](30) NOT NULL,
	[Emp_Surname] [varchar](30) NOT NULL,
	[Department] [varchar](50) NOT NULL,
	[Company] [varchar](30) NOT NULL,
	[Hostname] [nvarchar](20) NOT NULL,
	[Wkst_Status] [varchar](15) NOT NULL,
	[Make] [varchar](12) NOT NULL,
	[Model] [varchar](15) NOT NULL,
	[SerialNumber] [nvarchar](30) NOT NULL,
	[ProductNumber] [nvarchar](30) NOT NULL,
	[Purch_Date] [date] NOT NULL,
	[WExpiry_Date] [date] NOT NULL,
	[Memory] [nvarchar](6) NOT NULL,
	[Processor] [nvarchar](10) NOT NULL,
	[HDD] [nvarchar](10) NOT NULL,
	[OS] [nvarchar](25) NOT NULL,
	[Status_Id] [int] NOT NULL,
 CONSTRAINT [PK__Workstat__262359ABF6F5A9AA] PRIMARY KEY CLUSTERED 
(
	[Emp_Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Workstations]  WITH CHECK ADD  CONSTRAINT [FK__Workstati__Statu__6FE99F9F] FOREIGN KEY([Status_Id])
REFERENCES [dbo].[Status] ([Status_Id])
GO

ALTER TABLE [dbo].[Workstations] CHECK CONSTRAINT [FK__Workstati__Statu__6FE99F9F]
GO

AnswerRe: Cannot insert the value NULL into column 'Status_Id', table 'ITInventory.dbo.Workstations'; column does not allow nulls. INSERT fails. Pin
Richard Deeming20-May-19 8:43
mveRichard Deeming20-May-19 8:43 
QuestionAjax ToolKit File Upload CAN NOT upload AutoCAD files Pin
Member 1253746817-May-19 11:33
memberMember 1253746817-May-19 11:33 
AnswerRe: Ajax ToolKit File Upload CAN NOT upload AutoCAD files Pin
Richard Deeming21-May-19 0:39
mveRichard Deeming21-May-19 0:39 
Questionkeep web form drop down list from chagning Pin
dcof16-May-19 10:09
memberdcof16-May-19 10:09 
AnswerRe: keep web form drop down list from chagning Pin
Vinod Jangle28-May-19 10:41
memberVinod Jangle28-May-19 10:41 
QuestionRedirecting a user (vb.net) Pin
Member 876166712-May-19 23:22
memberMember 876166712-May-19 23:22 
AnswerRe: Redirecting a user (vb.net) Pin
Richard Deeming13-May-19 8:02
mveRichard Deeming13-May-19 8:02 
GeneralRe: Redirecting a user (vb.net) Pin
Member 87616679-Jun-19 23:56
memberMember 87616679-Jun-19 23:56 
QuestionEncountering error 401 1 2148074254 while accessing the webservice in NLB environment Pin
vinod koti7-May-19 3:22
membervinod koti7-May-19 3:22 
QuestionData Reader only producing one row of records. Any ideas why? Pin
samflex3-May-19 3:14
membersamflex3-May-19 3:14 
AnswerRe: Data Reader only producing one row of records. Any ideas why? Pin
Richard Deeming3-May-19 3:29
mveRichard Deeming3-May-19 3:29 
GeneralRe: Data Reader only producing one row of records. Any ideas why? Pin
samflex3-May-19 3:51
membersamflex3-May-19 3:51 
GeneralRe: Data Reader only producing one row of records. Any ideas why? Pin
Richard Deeming3-May-19 5:27
mveRichard Deeming3-May-19 5:27 
GeneralRe: Data Reader only producing one row of records. Any ideas why? Pin
samflex3-May-19 7:06
membersamflex3-May-19 7:06 
AnswerRe: Data Reader only producing one row of records. Any ideas why? Pin
jkirkerx3-May-19 9:18
professionaljkirkerx3-May-19 9:18 
GeneralRe: Data Reader only producing one row of records. Any ideas why? Pin
samflex3-May-19 9:51
membersamflex3-May-19 9:51 
GeneralRe: Data Reader only producing one row of records. Any ideas why? Pin
jkirkerx3-May-19 10:16
professionaljkirkerx3-May-19 10:16 

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.