本文介绍了如何在radiobutton中将值显示到文本框中并将值保存在ms访问中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好我的问题是如何在从RadioButon中选择的TextBox中显示一个值并将值保存到ms访问数据库中 我有什么试过: hi guys my problem is how to display a value in a TextBox selected from RadioButon and to save the value into ms access databaseWhat I have tried:Imports System.Data.OleDbImports System.Data.SqlClientPublic Class Form4 Public myconnection As String = "provider= Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Admin\Desktop\project database\Database5.accdb;Persist Security Info= false " Public conn As New OleDbConnection Public Sub insertdata() Try conn.ConnectionString = myconnection If conn.State = ConnectionState.Closed Then conn.Open() End If Dim myquary As String = " insert into registration([No],[PName],[RDate],[Gender],[DOB],[Address],[Phone],[Desease],[RoomNo],[Building],[RoomType],[Price]) Values (?,?,?,?,?,?,?,?,?,?,?,?)" Dim cmd As New OleDbCommand With cmd .CommandText = myquary .Connection = conn .Parameters.AddWithValue("@No", TextBox1.Text) .Parameters.AddWithValue("@PName", TextBox2.Text) .Parameters.AddWithValue("@RDate", TextBox3.Text) .Parameters.AddWithValue("@Gender", TextBox10.Text) .Parameters.AddWithValue("@DOB", TextBox4.Text) .Parameters.AddWithValue("@Address", TextBox5.Text) .Parameters.AddWithValue("@Phone", TextBox6.Text) .Parameters.AddWithValue("@Desease", TextBox9.Text) .Parameters.AddWithValue("@RoomNo", TextBox11.Text) .Parameters.AddWithValue("@Building", TextBox12.Text) .Parameters.AddWithValue("@RoomType", TextBox7.Text) .Parameters.AddWithValue("@Price", TextBox8.Text) ------------------------- ------------------------------------------------ 我得到的错误是:与数据表达式不匹配-------------------------------------------------------------------------the error i'am getting is :mismatch into data expression推荐答案 Dim myquary As String = " insert into registration([No],[PName],[RDate],[Gender],[DOB],[Address],[Phone],[Desease],[RoomNo],[Building],[RoomType],[Price]) Values (?,?,?,?,?,?,?,?,?,?,?,?)" Dim cmd As New OleDbCommand With cmd .CommandText = myquary .Connection = conn .Parameters.AddWithValue("@No", TextBox1.Text) 有两种解决方法: 1.使用命名参数 There's 2 ways to resolve it:1. Use named parameters Dim myquary As String = " insert into registration([No],[PName],[RDate],[Gender],[DOB],[Address],[Phone],[Desease],[RoomNo],[Building],[RoomType],[Price]) Values (@No,...)" Dim cmd As New OleDbCommand With cmd .CommandText = myquary .Connection = conn .Parameters.AddWithValue("@No", TextBox1.Text) 或 2.插入非命名参数。重要说明:您必须按照与字段相同的顺序添加它们 or2. Insert non-named parameters. Important note: you have to add them in the same order as fieldsDim myquary As String = " insert into registration([No],[PName],[RDate],[Gender],[DOB],[Address],[Phone],[Desease],[RoomNo],[Building],[RoomType],[Price]) Values (?,?,?,?,?,?,?,?,?,?,?,?)" Dim cmd As New OleDbCommand With cmd .CommandText = myquary .Connection = conn .Parameters.Add(New OleDbParameter("@p1", TextBox1.Text)) b $ b 请参阅: OleDbParameter类(System.Data.OleDb) [ ^ ] 这篇关于如何在radiobutton中将值显示到文本框中并将值保存在ms访问中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 05:06