Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9284383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:53:15+00:00 2026-06-18T18:53:15+00:00

In here i need to create a DataTable,But it doesn’t return a id.There’s no

  • 0

In here i need to create a DataTable,But it doesn’t return a id.There’s no error.Actually here i provide a email address(epost).and i need to return id from database.

Coding Part Goes Here.

public string GetAllMails()
    {
        DataConnection dc = new DataConnection();

        string e="";
        int uid=-1,sid=0;

        DataTable dt = new DataTable();
        dt.Columns.Add("id");
        dt.Columns.Add("uid");
        dt.Columns.Add("email");

        Microsoft.Office.Interop.Outlook.Application oApp;
        Microsoft.Office.Interop.Outlook._NameSpace oNS;
        Microsoft.Office.Interop.Outlook.MAPIFolder oFolder;
        Microsoft.Office.Interop.Outlook._Explorer oExp;

        oApp = new Microsoft.Office.Interop.Outlook.Application();
        oNS = (Microsoft.Office.Interop.Outlook._NameSpace)oApp.GetNamespace("MAPI");
        oFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
        oExp = oFolder.GetExplorer(false);
        oNS.Logon(Missing.Value, Missing.Value, false, true);

        Microsoft.Office.Interop.Outlook.Items items = oFolder.Items;

        SqlConnection conn = dc.SqlConnection;
        if (conn.State != ConnectionState.Open) conn.Open();
        SqlCommand cmd = new SqlCommand("GetDetailsByEmail", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter param = new SqlParameter();

        foreach (Microsoft.Office.Interop.Outlook.MailItem mail in items)
        {
            if (mail.UnRead == true)
            {
                e=mail.SenderEmailAddress;

               // param   <-- add sql parameters
                cmd.Parameters.Add(new SqlParameter("@epost",e));

                uid = cmd.ExecuteNonQuery();

                //send to db and take the id (uid)

                //if returned id
                DataRow row = dt.NewRow();

                row["id"] = sid;
                sid++;

                row["uid"] = uid;// uid

                row["email"] = e;

                dt.Rows.Add(row);

            }
        }

        return e;
    }

Stored Procedure goes here

ALTER Procedure [dbo].[GetDetailsByEmail]

@epost nvarchar(50)

AS
BEGIN
Select Medlems_ID,[E-post]
from dbo.Members
where [E-post] = @epost
END

When i edit my coding,uid is a int.

uid = cmd.ExecuteReader(); or uid = cmd.ExecuteScalar(); // it shows me conversion error.here i put as a comment
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:53:17+00:00Added an answer on June 18, 2026 at 6:53 pm

    If you read the documentation for ExecuteNonQuery you will see the line:

    Executes a Transact-SQL statement against the connection and returns the number of rows affected.

    You need to use SqlCommand.ExecuteReader to do what you want.

    EDIT:

    Here is how your code could look based on your comment. It is a bit strange that your sproc returns 2 columns but you are only interested in 1. Also it is not clear if you expect multiple rows or not.

    if (dc.SqlConnection.State != ConnectionState.Open) 
        dc.SqlConnection.Open();
    
    using (var cmd = new SqlCommand("GetDetailsByEmail", dc.SqlConnection))
    {
        cmd.CommandType = CommandType.StoredProcedure;
    
        foreach (Microsoft.Office.Interop.Outlook.MailItem mail in items)
        {
            if (mail.UnRead)
            {
                e = mail.SenderEmailAddress;
    
                //this is a little nasty
                if (cmd.Parameters.Count > 0)
                    cmd.Parameters.RemoveAt(0);
    
                cmd.Parameters.AddWithValue("@epost", e);
    
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        uid = reader.GetInt32(0);
    
                        DataRow row = dt.NewRow();
                        row["id"] = sid;
                        sid++;
                        row["uid"] = uid;// uid
                        row["email"] = e;
                        dt.Rows.Add(row);
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create next and previous link urls here's a sample <a href=/calendar/2009/10/>previous</a>
here i need a batch file which can apply and create label or base
Here is the reference tutorial Do I need to create django_login and edit the
My problem : I need to create draggable widgets (here it's a jslider for
Here is my situation. I need to create a report that shows each open
Ok, so here's the entire structure I'm trying to create. I need to create
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
I need to create an excel file from scratch in VB.NET given a DataTable
I am developing a php web site. Here I need to create thumbnail of
I'm converting an existing program to C++ and here need to manipulate Sybase timestamps.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.