dimanche 28 juin 2015

Error in Updating a Record

Hello Everyone I'm new in here. I am currently making an asp.net project monitoring module. At this moment I am in the process of editing the project form and adding resources to the selected task in a project.

I'm having a problem in saving the record. Everytime I save the record it says

"Column name or number of supplied values does not match table definition."

In my ProjectTasks Table I have RefNo(PK), TaskID(FK), Name and Description

Name - refers to the Task Name

Description - refers to the Task Description

What I want to happen is that my Resource Tables TaskID(FK) will be updated when I clicked the save button. As of now when I add a Resource from a task the TaskID = 0.


protected void btnSave_Click(object sender, EventArgs e)
{
    con.Open();
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandText = "INSERT INTO ProjectTasks VALUES (@Name, @Description); " +
    "SELECT TOP 1 TaskID FROM ProjectTasks ORDER BY TaskID DESC;";
    cmd.Parameters.AddWithValue("@Name", txtName.Text);
    cmd.Parameters.AddWithValue("@Description", txtDescription.Text);
    int taskID = (int)cmd.ExecuteScalar();
    con.Close();

    con.Open();
    cmd.CommandText = @"UPDATE Resource_Materials SET TaskID=@TaskID WHERE TaskID=0; " +
                        "UPDATE Resource_Equipments SET TaskID=@TaskID WHERE TaskID=0; " +
                        "UPDATE Resource_Vehicles SET TaskID=@TaskID WHERE TaskID=0; " +
                        "UPDATE Resource_Contractors SET TaskID=@TaskID WHERE TaskID=0;";
    cmd.Parameters.AddWithValue("@TaskID", taskID);
    cmd.ExecuteNonQuery();
    con.Close();
    Helper.AddLog("1", "Add", "Assigned Resources to Task");
    Response.Redirect("~/Projects/Default.aspx");
}


Sorry about my grammar I'm just a student.

How to change the SqlStatementSource in a SSIS package through job step advanced tab

I have a ssis package deployed and created a sql agent job which executes the package.I need to change the SqlStatementSource in one of the sql task in package through job step advanced tab. Can any one help me how to do that? I somewhere read its possible but not able to recall how exactly it can be done?

Writing a query to display the following result?

There are 3 tables:

Table A:

code    aname
------- ---------
1       A
2       B
3       C

Table B:

code        bname
----------- ----------
1           aaa
1           bbb
2           ccc
2           ddd

Table C:

code        cname
----------- ----------
1           xxx
1           yyy
1           zzz
2           www

We need to write a query that would display the following result:

code        aname      bname            cname
----------- ---------- ----------      ----------
1           A          aaa              xxx
1           A          bbb              yyy
1           A          NULL             zzz
2           B          ccc              www
2           B          ddd              NULL
3           C          NULL             NULL

SQL Server Database recovery from corrupt database

Last week I backed up my SQL Server by using Backup Exec 2012. I named the file "SQL Server BAK" which contained copies of my SQL Server databases. A few days ago I lost some part of my data due to accidental deletion. I backed it up, so I tried to restore the database from the .bkf file. The problem comes here, when I try to to restore my .bkf file, it becomes inaccessible.

Does anyone know what causes this? I'm suspecting corruption here (it's just a suspicion as I'm not sure). Please help me. The copies of my databases are very crucial.

Many thanks in advance.

SQL Server float data type understanding

http://ift.tt/1fY2rQ0

After I insert a value (0.12346789123456789123456789) for example in the table that has a float type column, I query and get back 0.1234567891234568 which contains 17 digits. I have 3 questions

  1. How can I back track the binary representation of the input and output ? The document says it uses 53 bits as default. I am using Management Studio SQL Server and I don't know how to specify n value during declaration of my column type.
  2. The number 17 isn't included in the document, I wish to know where it comes from.
  3. In Big or Little Endian systems, I'd like to know how such an input is treated and translated into the output at the low-level byte system. If anyone knows an explanation, I would be thankful.

Why there is a shift from SQL only server to Aerospike or Crate which are hybrids?

What are the use cases where hybrid databases like Aerospike and Crate would out perform compared to SQL DBs? Can someone who have worked with any one (or both) list down the pros/cons of using such DBs?

Will migrating from MSSQL to Aerospike require much of an effort? or will it be even feasible?

Unable to get data from stored procedure

I'm trying to hit the stored procedure from C# code but always get the result == -1. I don't know where I went wrong. I have searched a lot but didn't' find any solution. Please have a look into my code snippet and guide me what I'm doing wrong.

Thanks in advance.

C# code:

using (SqlConnection connection = new SqlConnection(getConnectionString()))
using (SqlCommand command = new SqlCommand())
{
    Int32 rowsAffected;

    command.CommandText = "SP_LOGIN_GETUSERBYNAME";
    command.CommandType = CommandType.StoredProcedure;
    // command.Parameters.Add(new SqlParameter("@Email", userObj.email));
    // command.Parameters.Add("@Email", SqlDbType.VarChar).Value = userObj.email.Trim();
    command.Parameters.AddWithValue("@Email", userObj.email.ToString());
    command.Connection = connection;

    connection.Open();
    rowsAffected = command.ExecuteNonQuery();
    connection.Close();

    return rowsAffected;
}

Connection string:

return "Data Source=MUNEEB-PC;Initial Catalog=HRPayRoll;User ID=sa; Password=sa";

Stored procedure code:

CREATE PROCEDURE SP_LOGIN_GETUSERBYNAME
    @Email varchar(50)
AS
    SELECT *
    FROM [User]
    WHERE Email = @Email
GO