views:

73

answers:

3

SO I'm making a "basic" login file where a person logs in and the data that person entered on that form gets transfered to another form aka my database/table.

I think the problems is here but I'll post the rest of the code.

CREATE FUNCTION dbo.Function4
 (

 parameter1 int = 5,
 parameter2 datatype

 )
RETURNS Table1 TABLE (UserName, Password, Password_Confirmation, Assets)
AS
 BEGIN
   INSERT INTO Table1
   (UserName, Password, Password_Confirmation, Assets)
   VALUES
   (a,b,c,d);
     /*SELECT ... FROM ...*/
 RETURN
 END

This is the Login Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Login_Basic
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        Form3 Delta = new Form3();

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void Form2_Load(object sender, EventArgs e)
        {
            this.Hide();

        } 

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
        {
            int i = Convert.ToInt32(e.KeyChar);
            if (!(Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar) || (e.KeyChar == '.' && this.Text.Contains(".") == false)))
                e.Handled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Delta.Show();



            //if (textBox3.Text.Equals(""))
            //{
            //    MessageBox.Show("Please enter your username");
            //}
            //else
            //{
            //    this.Hide();
            //}



           // if (textBox4.Text.Equals(""))
            //{
            //    MessageBox.Show("Please enter your password");

           // }
           // else
            //{
            //    this.Hide();
           // }

           // if (textBox5.Text.Equals(""))
           // {
           //     MessageBox.Show("Please re-enter your password");

           // }
           // else
           // {
           //     this.Hide();
           // }

            //if (textBox6.Text.Equals(""))
            //{
           //     MessageBox.Show("Please enter your amount");
           //     
           // }
           // else
           // {
           //     this.Hide();
           // }



        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {
            /*if (textBox3.Text.Equals("") && textBox4.Text.Equals("") && textBox5.Text.Equals("") && textBox6.Text.Equals(""))
            {
                button1.Enabled = false;

            }
            else
            {
                button1.Enabled = true;


            }*/
        }
    }
}

Here's a "Pic" of my database

http://s299.photobucket.com/albums/mm305/krsimms123/Code.jpg

Thanks in advance (I'll try and check this every few hours so I can help explain anything)

A: 

your function is inserting (a, b, c, d)?

CREATE FUNCTION dbo.Function4( )
RETURNS Table1 TABLE (UserName, Password, Password_Confirmation, Assets)
AS
 BEGIN
   SELECT UserName, Password, Password_Confirmation, Assets FROM Table1
   RETURN
 END
Glennular
+2  A: 

I was under the impression that you cannot update or insert records from a TSQL function.

See this link

User-defined functions cannot be used to perform a set of actions that modify the global database state. User-defined functions, like system functions, can be invoked from a query. They also can be executed through an EXECUTE statement like stored procedures.

ADDED:

You need to use a stored procedure as Meff pointed out below.

CREATE PROCEDURE InsertLoginAttempt
    @UserName nvarchar(25)
    @Password nvarchar(25)
AS
    INSERT INTO Table1 (UserName, Password)
    VALUES (@UserName, @Password)

See this link on how to call a stored proc from .net

Tim Santeford
Just spotted that but you beat me to it. He wants a stored procedure for INSERTS.
Meff
A: 

a,b,c,d where just me trying to get something to display

If someone could tell me how to get what's displayed in the UserName Textbox (textbox3 in Form 2) into the Table under USername I could probably do the rest myself thanks

Erebus