Cannot implicitly convert type 'void' to 'int'?

前端 未结 3 1884
深忆病人
深忆病人 2021-01-16 11:32

Oke so I am fairly new to programming and I don\'t get why I get this error.

My method should store mails which it does in this method:

    public vo         


        
3条回答
  •  没有蜡笔的小新
    2021-01-16 12:04

    In my case I created stored procedure in the database SQL server , then i created a class in c# program and called this stored procedures and add the parameter in the stored procedures inside the class and return the data in the data table ,finally i can call my class any where in my program like this example :

    1- Create Stored Procedure :

    CREATE proc [dbo].[GET_SAMPLE_KIND]
    @TESTID int
    as 
    select Dept_id,ID_sample from LabTests
    where LabTests.TestId = @TESTID 
    

    2- Create class in your C# program and call the stored procedure with parameters like this code :

    public DataTable GET_SAMPLE_KIND(int TESTID)
            {
                DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
                DataTable dt = new DataTable();
    
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@TESTID", SqlDbType.Int);
                param[0].Value = TESTID;
    
                dt = DAL.SelectData("GET_SAMPLE_KIND", param);
                DAL.close();
                return dt;
            }
    

    To connect and read from database you must make another class to contact sql server which is in my case DAL.selectData method to select data from database , also for insert and update and delete statements you can create stored procedures then create another void in your class for that functions.

    3- Finally you can call your class and stored procedures from your program.

提交回复
热议问题