.NET Programming

134K

Solutions

39K

Contributors

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,

I am trying to create a CLR function to allow users to grab data from a table that changes names each month (name changes are outside my control).

I have everything compiling and running without any errors but I never get any rows back.

I have simplified things as much as possible to try to find the problem and am inserting a DataRow into the DataTable I want to return to rule out problems with the select but still don't get any rows.

C# code
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.IO;
using Microsoft.SqlServer.Server;


public class TableFunctions
{

    [SqlFunction(FillRowMethodName = "FillCLRTest")]
    public static IEnumerable CLRTest()
    {
        string query = "SELECT [id]" +
                "FROM table";

        DataTable results = new DataTable();

        try
        {
            using (SqlConnection conn = new System.Data.SqlClient.SqlConnection("context connection = true"))
            using (SqlCommand command = new SqlCommand(query, conn))
            using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
                dataAdapter.Fill(results);

            DataRow dummyRow = results.NewRow();

            dummyRow[0] = "1234";
            results.Rows.Add(dummyRow);

            return results.Rows;

        }
        catch (Exception e)
        {

        }

        return null;


    }

    public static void FillCLRTest(Object 

Open in new window

0
Build an E-Commerce Site with Angular 5
LVL 13
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

I am iterating through a text file using VB.net. Some of the numeric values are stored as strings. I would like to use the VB.net command Convert.ToSingle to convert the string input into a decimal(Or floating point number). How shall I handle the case when the string value is not numeric, because an exception will be thrown? I wish there was a command that could in effect look ahead to determine if the value is not numeric.



Dim num As Single
num - Convert.ToString(inString) ' Exception thrown here if the inString value is not numeric
0
I have a feeling I might be going about this the wrong way. I'm hoping there's a solution to what I want to accomplish.

I have the following colors defined in a resource dictionary
    <SolidColorBrush x:Key="Add.Border" Color="#FF4BAE53"/>
    <SolidColorBrush x:Key="Add.Background" Color="#FF5BB862"/>
    <SolidColorBrush x:Key="Add.Hover" Color="#FF439D4B"/>
    <SolidColorBrush x:Key="Add.Pressed" Color="#FF38843E"/>
    <SolidColorBrush x:Key="Add.Disabled" Color="#A55BB862"/>
    <SolidColorBrush x:Key="Add.Foreground" Color="White"/>

    <SolidColorBrush x:Key="Edit.Border" Color="#FFECA040"/>
    <SolidColorBrush x:Key="Edit.Background" Color="#FFEEAC55"/>
    <SolidColorBrush x:Key="Edit.Hover" Color="#FFEA952E"/>
    <SolidColorBrush x:Key="Edit.Pressed" Color="#FFD38323"/>
    <SolidColorBrush x:Key="Edit.Disabled" Color="#A5EEAC55"/>
    <SolidColorBrush x:Key="Edit.Foreground" Color="White"/>

    <SolidColorBrush x:Key="Delete.Border" Color="#FFD33B3B"/>
    <SolidColorBrush x:Key="Delete.Background" Color="#FFD85050"/>
    <SolidColorBrush x:Key="Delete.Hover" Color="#FFC82B2D"/>
    <SolidColorBrush x:Key="Delete.Pressed" Color="#FFAA2526"/>
    <SolidColorBrush x:Key="Delete.Disabled" Color="#A5D85050"/>
    <SolidColorBrush x:Key="Delete.Foreground" Color="White"/>

Open in new window

I'm creating a custom control that will use these colors as a palette. The actual colors it will use will be determined by a property I'm calling "Purpose". That purpose will be Add, Edit, or Delete. I already have that property working. What I don't have working is being able to select the Delete.Background color if the value of "Purpose" is Delete vs. the Add.Background color if the value is Add. Is this even possible? Is there perhaps another way I should be defining my colors in the resource dictionary to make this work properly?
0
Using Microsoft .NET Framework Version 4.8.03752 I performed a [successful] FTP upload.  How do I compare the source and the target to verify they match?
1
Hi,
How do i pick up the default printer and print the image in the picture box.
I am using vb.net
0
I'm still learning the mechanics of this whole WPF thing. I'm creating a user control. One of the things I want my control to be able to do is respond to click events of a control on the parent window. To do this, I have created a property called "Activator" like this:
		public DependencyObject Activator { get; set; }
		public static readonly DependencyProperty ActivatorProperty = DependencyProperty.Register("Activator", typeof(DependencyObject), typeof(NavView));

Open in new window

I then markup my Xaml like this:
                <Button Name="buttonShowHideMyControl" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Style="{DynamicResource HeaderButton}" Grid.ColumnSpan="2" Margin="0,4,9,0">
                    <fa:FontAwesome Grid.Column="2" Icon="Bars" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="White" FontSize="24" Margin="10,4,0,4"/>
                </Button>
            <local:TestUserControl x:Name="testUC" Grid.Column="1" HorizontalAlignment="Right" Visibility="Hidden" Opacity="0" Activator="{Binding Property, ElementName=buttonShowHideMyControl}">
                
            </local:TestUserControl>

Open in new window

0
Can you please tell me why this routine is not showing values in the text box when i click in the text area?
screenshot.JPG
      private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox i = sender as ListBox;
            if (i.SelectedIndex != -1)
            {
                listBox1.SelectedIndex = i.SelectedIndex;
                listBox2.SelectedIndex = i.SelectedIndex;
                txtID.Text = listBox1.SelectedItem.ToString();
                txtName.Text = listBox2.SelectedItem.ToString();               
            }
        
        }

Open in new window

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;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, 

Open in new window

0
Can you please help me in that error?
screenshot.JPG
namespace InsertUpdateDel
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.txtID = new System.Windows.Forms.TextBox();
            this.txtName = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.listBox2 = new System.Windows.Forms.ListBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            

Open in new window

0
Can you please help me in that error?
Error in List Box[code]
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;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtID.Text != "" & txtName.Text != "")
            {
                cn.Open();
                cmd.CommandText = "Insert into info(id, name) values ('" +txtID.Text+"', '" +txtName.Text+"')";
                cmd.ExecuteNonQuery();
                cmd.Clone();
                MessageBox.Show("Record Inserted", "Programming");
                cn.Close();
                txtID.Text="";
                txtName.Text="";
                loadlist();
            }
        }
        …
0
Can you please tell me what this error means?

Error statement: sd = cmd.ExecuteReader();

screenshot.JPG
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;
using System.Data.SqlClient;

namespace InsertUpdateDel
{
    public partial class Form1 : Form
    {
        SqlConnection cn = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter sd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
                cmd.Connection = cn;
                loadlist();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtID.Text != "" & txtName.Text != "")
            {
                cn.Open();
                cmd.CommandText = "Insert into info(id, name) values ('" +txtID.Text+"', '" +txtName.Text+"')";
                cmd.ExecuteNonQuery();
                cmd.Clone();
                MessageBox.Show("Record Inserted", "Programming");
                cn.Close();
                txtID.Text="";
                txtName.Text="";
                loadlist();
            }
        }

Open in new window

0
Learn Ruby Fundamentals
LVL 13
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Using VS 2012 Professional.  Can't build a winforms application.  

Receiving error:  "Couldn't process file xxxx.resx due to its being in the Internet or Restricted zone or having the mark of the web on the file.  Remove the mark of the web if you want to process these files".

I tried adding to the local intranet -> file://computername like example below but didn't work.  I also tried to right click, properties, but there was NO unblock checkbox.

https://developercommunity.visualstudio.com/content/problem/291761/couldnt-process-file-abcresx-due-to-its-being-in-t.html

Any idea how to resolve.  This is a production problem for me.
0
I have a checkbox panel and I am adding the text for check box like this

chkPanel.Controls.Add(new CheckBox { Text = "Savings" + "This text needs to be red and bold", Checked = true, Enabled = false });
chkPanel.Controls.Add(new LiteralControl("<br />"));
chkPanel.Controls.Add(new CheckBox { Text = "Checking" , Checked = false, Enabled = false });


where you see "This text needs to be red and bold"  i actually want that text to be red and bold.  is it possible. if yes how?
0
In visual studio 2019  how to set auto incrementing build number or version number.
Thanks
0
Is "odeskwork" a freelancing website completely separate from "upwork"?  

Can USA freelancers join odeskwork site?
0
Forgive my ignorance. I'm still learning xaml.

I have this button:
                <Button Name="CloseButton" DockPanel.Dock="Top" HorizontalAlignment="Right" Style="{StaticResource TitleBarButton}" Click="CloseButton_Click" Tag="Images/Window/close.png">
                </Button>

Open in new window

This is the style definition I have so far:
    <Style x:Key="TitleBarButton" TargetType="Button">
        <Setter Property="Width" Value="34"/>
        <Setter Property="Height" Value="26"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="1,0,1,1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border x:Name="border" Background="Transparent" BorderBrush="Transparent" BorderThickness="1,0,1,1" >
                        <Image Source="{Binding Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" Stretch="None"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Background.Color" To="#FFFFFCF4" Duration="0:0:0.2"/>
                          

Open in new window

1
Hi
In the code bellow I'm getting null because the profile path in the database can be  null

How do I test for this so it dosn't throw a  NullReferenceException

as can be seen in the picture person isn't null person.JPG

        public ActorBox(person person)
        {
            InitializeComponent();
            this.person = person;
            if( (person.profile_path.EndsWith( "JohnWayneBig.png")) || ( person.profile_path is null) )
            {
                ThumbPhotoPath = ImgPath + "JohnWayneSml.png";
                FullPhotoPath = ImgPath + "JohnWayneBig.png";

            }
            else
            {
                ThumbPhotoPath = ImgURL + "w45" + person.profile_path;
                FullPhotoPath = ImgURL + "original" + person.profile_path;
            }
            

            ThumbPictureBox.LoadAsync(ThumbPhotoPath);
            ActorNameLbl.Text = person.name;
        }

Open in new window



System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=FilmsDB
  StackTrace:
   at FilmsDB.ActorBox..ctor(person person) in D:\Vb\MovieDB\FilmsDB\ActorBox.cs:line 34

Open in new window

0
I have added a new project to Team Foundation server(Source Control Explorer). I have not checked it in though. The new project and code has a litter green plus sign next to it.

So if I have not checked in the code yet, can I delete the code which was added in Source Control Explorer?
0
Using VB.NET  (Visual Studio 2019) in windows form how I can update the app.config file?  somebody know an example
0
Hello,
In a datetime field how do I determine if the time is between
00:00  to 2:45

example:
Datetime Field :  23/09/2019 00:15
The value is between 00:00  to 2:45
 and should return true

example2:
Datetime Field :  23/09/2019 01:15
The value is between 00:00  to 2:45
 and should return true


example3:
Datetime Field :  23/09/2019 02:46
The value is not between 00:00  to 2:45
 and should return false
0
Bootstrap 4: Exploring New Features
LVL 13
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Set datacolumn to date in vb.net
0
Hi All

As mentioned in Internet, LiteDB dll can be used with Dot Net Framework 3.5 but I am facing issue while doing same though the LiteDB dll is working fine with framework 4.0. Can anyone guide on same?

I am trying to use DLL Version 4.1.4.0.

Thanks.
0
I have a Async Function that references a control on the screen.  The control is updated with new information during the running of the function.  Do I place the Await Task.Delay(1) before or after the control is updated?

Btn.text = "One" : Await Task.Delay(1)

or

Await Task.Delay(1) : Btn.text = "One"
0
HOW WOULD YOU RESTRUCTURE THE DATA IN ACCESS or SQL SERVER IN ORDER TO EXECUTE THIS QUERY

QUERY--> "what is the effect of brain region, target location, and timing on kinematic response?"

ID      Parameter      UT_50      UT_0      UT_100      UT_250      MT_50      MT_0      MT_100      MT_250      LT_50      LT_0      LT_100      LT_250
20130318ED      DLPFC 100ms angle      12.32174145      12.99330841      9.198294504      11.52222631      6.340282729      5.765893345      2.356281523      2.816760675      15.21706611      11.67522974      37.53215703      28.62763514
20130415AV      DLPFC 100ms angle      6.643960487      2.681605064      45.47663277      13.03811801      11.46481681      11.70855284      16.70370681      21.46583857      4.024752731      20.52851436      12.07552518      18.812411
20130422PS      DLPFC 100ms angle      27.05474266      24.54031814      13.64629434      22.24167306      17.14609102      10.07054778      7.698115749      15.96791456      12.69933214      29.42852496      13.32754867      13.01389084
20130429AB      DLPFC 100ms angle      13.31082269      11.91017544      6.457531213      9.531094567      6.056097826      8.80621661      6.886299206      7.711310657      3.729936749      3.01717473      6.905232067      9.607273808
20130506JN      DLPFC 100ms angle      5.049545403      5.967528912      3.863780423      15.23849361      12.90741906      11.2606615      6.935865509      8.657818408      4.562420907      24.74435935      14.83554088      18.92366217
20130513WD      DLPFC 100ms angle      36.70301022      26.63866007      14.64716985      6.896767072      62.75687098      17.76465364      23.02631308      34.29193975      18.95470209      15.6362619      5.463278143      21.88485651
20130523VL      DLPFC 100ms angle      16.56186768      3.067840624      17.52907656      15.09035332      8.630383858      16.48188211      7.649123584      18.03464645      37.87583362      10.83250461      25.90015454      21.33974508
0
I'm creating a custom drawn form with its own title bar, footer, resizability, all that fun stuff. I've overridden the WndProc method of the form as follows:
		protected override void WndProc(ref Message m)
		{
			if (m.Msg == WM_NCHITTEST)
			{
				Point cursorPosition = new Point(m.LParam.ToInt32());
				cursorPosition = this.PointToClient(cursorPosition);
				Point resizeZone = new Point(this.FooterRectangle.Right - 16, this.FooterRectangle.Bottom - 16);
				System.Diagnostics.Debug.Print($"{resizeZone} - {cursorPosition}");
				if (cursorPosition.Y <= TITLEBAR_HEIGHT)
				{
					m.Result = (IntPtr)2;
					return;
				}
				if (cursorPosition.X >= resizeZone.X && cursorPosition.Y >= resizeZone.Y)
				{
					this.Cursor = Cursors.SizeNWSE;
					m.Result = (IntPtr)17;
					return;
				}
				else
				{
					this.Cursor = Cursors.Arrow;
				}
			}
			base.WndProc(ref m);
		}

Open in new window

This does a great job of allowing me to drag or resize the window but the one thing that's currently missing is being able to display the window context menu on either a right click or when left clicking on the form's icon in the upper left corner. (Screenshot attached for clarity). Can anyone tell me how this might be accomplished?
Window context menu
0
Hello,
Is there a better and faster way of Application.doevents
Thanks
0

.NET Programming

134K

Solutions

39K

Contributors

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.