ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Error: not all code paths return a value<blockquote><cite>micah says:</cite> <div class="line number25 index24 alt2"><code class="csharp keyword">public</code> <code class="csharp plain">DataTable GetProfile(</code><code class="csharp keyword">string</code> <code class="csharp plain">username)</code></div> <div class="line number26 index25 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number27 index26 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">SqlConnection constr = </code><code class="csharp keyword">new</code> <code class="csharp plain">SqlConnection(ConfigurationManager.ConnectionStrings[</code><code class="csharp string">"conn"</code><code class="csharp plain">].ConnectionString);</code></div> <div class="line number28 index27 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">DataSet Dset = </code><code class="csharp keyword">new</code> <code class="csharp plain">DataSet();</code></div> <div class="line number29 index28 alt2">&nbsp;</div> <div class="line number30 index29 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">SqlDataAdapter adapt;</code></div> <div class="line number31 index30 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">Dset.Clear();</code></div> <div class="line number32 index31 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">adapt = </code><code class="csharp keyword">new</code> <code class="csharp plain">SqlDataAdapter(</code><code class="csharp string">"GetUserPOSTS"</code><code class="csharp plain">, constr);</code></div> <div class="line number33 index32 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">adapt.Fill(Dset, </code><code class="csharp string">"GetUserPOSTS"</code><code class="csharp plain">);</code></div> <div class="line number34 index33 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">adapt.SelectCommand.CommandType = CommandType.StoredProcedure;</code></div> <div class="line number35 index34 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">adapt = </code><code class="csharp keyword">new</code> <code class="csharp plain">SqlDataAdapter(</code><code class="csharp string">"GetADPOST"</code><code class="csharp plain">, constr);</code></div> <div class="line number36 index35 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">adapt.Fill(Dset, </code><code class="csharp string">"GetADPOST"</code><code class="csharp plain">);</code></div> <div class="line number37 index36 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">adapt.SelectCommand.CommandType = CommandType.StoredProcedure;</code></div> <div class="line number38 index37 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp comments">// adp.SelectCommand.Parameters.AddWithValue("@Email", username);</code></div> <div class="line number39 index38 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">adapt.SelectCommand.Parameters.AddWithValue(</code><code class="csharp string">"@UserName"</code><code class="csharp plain">, username);</code></div> <div class="line number40 index39 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">adapt.SelectCommand.Parameters.AddWithValue(</code><code class="csharp string">"@Id"</code><code class="csharp plain">, Id);</code></div> <div class="line number41 index40 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">DataTable table1 = </code><code class="csharp keyword">new</code> <code class="csharp plain">DataTable();</code></div> <div class="line number42 index41 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">DataTable table2 = </code><code class="csharp keyword">new</code> <code class="csharp plain">DataTable();</code></div> <div class="line number43 index42 alt2">&nbsp;</div> <div class="line number44 index43 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">table1 = Dset.Tables[0];</code></div> <div class="line number45 index44 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">table2 = Dset.Tables[1];</code></div> <div class="line number46 index45 alt1">&nbsp;</div> <div class="line number47 index46 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">table2.Merge(table1);</code></div> <div class="line number48 index47 alt1">&nbsp;</div> <div class="line number49 index48 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">GetMergedAll.DataSource = table2;</code></div> <div class="line number50 index49 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">GetMergedAll.DataBind();</code></div> </blockquote> <p>&nbsp;Replace the above method with the below.</p> <pre class="brush: csharp">public DataTable GetProfile(string username) { SqlConnection constr = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;conn&#34;].ConnectionString); DataSet Dset = new DataSet(); SqlDataAdapter adapt; Dset.Clear(); adapt = new SqlDataAdapter(&#34;GetUserPOSTS&#34;, constr); adapt.Fill(Dset, &#34;GetUserPOSTS&#34;); adapt.SelectCommand.CommandType = CommandType.StoredProcedure; adapt = new SqlDataAdapter(&#34;GetADPOST&#34;, constr); adapt.Fill(Dset, &#34;GetADPOST&#34;); adapt.SelectCommand.CommandType = CommandType.StoredProcedure; // adp.SelectCommand.Parameters.AddWithValue(&#34;@Email&#34;, username); adapt.SelectCommand.Parameters.AddWithValue(&#34;@UserName&#34;, username); adapt.SelectCommand.Parameters.AddWithValue(&#34;@Id&#34;, Id); DataTable table1 = new DataTable(); DataTable table2 = new DataTable(); table1 = Dset.Tables[0]; table2 = Dset.Tables[1]; table2.Merge(table1); return table2; }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/415924/Error-not-all-code-paths-return-a-value/https://www.aspforums.net:443/Threads/415924/Error-not-all-code-paths-return-a-value/Thu, 10 Nov 2016 03:21:03 GMT