Home Ask Login Register

Developers Planet

Your answer is one click away!

Squirmster February 2016

Cannot convert from 'void' to 'string' error message

I am trying to get an App to connect to an oracle database and found a lovely tutorial here: Tutorial is here.

I am not a programmer, but have plugged in into my program and I am getting an error message

argument 1: cannot convert from'void' to 'string'

in the bit where I am calling the connect and query method. Any advice on how to fix the issue?

The problem is from when I try to call the ConnectAndQuery method to show the results.

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

namespace SQLConnect3
public partial class UpdatePOsNewUser : Form
    int sum = 0;

    public UpdatePOsNewUser()

    private static string CONNECTION_STRING =
        "User Id=MyUser;Password=MyPassword;Data Source=(DESCRIPTION=" +
        "(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))" +

    // This really didn't need to be in its own method, but it makes it easier 
    // to make changes if you want to try different things such as
    // promting the user for credentials, etc.

    static private string GetConnectionString()
        // To avoid storing the connection string in your code, 
        // you can retrieve it from a configuration file. 
        return "Data Source=myserver.server.com;Persist Security Info=True;"              +
               "User ID=myUserID;Password=myPassword;Unicode=True";

    // This will open the connection and query the database
    static private void ConnectAndQuery()
        string connectionString = GetConnectionString();
        using (OracleConnection connection = new O        


David February 2016

This method doesn't return anything (hence, void):

static private void ConnectAndQuery()

But you're trying to use its return value here:


What exactly do you expect to show in the message box if there's no return value?

If you want the method to return a string, change its signature from void to string and then return a string value in the method.

HimBromBeere February 2016

Obviously you want to show a message using MessageBox.Show(ConnectAndQuery());. However the Show-message expects a string a s parameter, but you assign a call to a method returning nothing (void). I assume you simply want to call the ConnectAndQuery-method and afterwards show any log-message:


Thomas February 2016

This line MessageBox.Show(ConnectAndQuery()); is the source of your problem. MessageBox.Show takes a String and you're giving it a void.

Post Status

Asked in February 2016
Viewed 1,676 times
Voted 14
Answered 3 times


Leave an answer

Quote of the day: live life